$(document).ready(function() {

	
	
	
	
	$("label.overlabel").overlabel();

	$(".news-gallery .g-cont").scrollable({
		size: 3
	}).circular();

	$(".navigation ul").lavaLamp({ fx: "easeInOutCirc", speed: 200 });

	$(".gallery_main").scrollable({

		// basic settings
		size: 1,
		clickable: false,

		// up/down keys will always control this scrollable
		keyboard: 'static',

		// assign left/right keys to the actively viewed scrollable
		onSeek: function(event, i) {
			horizontal.scrollable(i).focus();
		}

		// main navigator (thumbnail images)
	}).navigator(".gallery_navi ul");

	// horizontal scrollables. each one is circular and has its own navigator instance
	var horizontal = $(".scrollable").scrollable({size: 1,clickable: false}).circular().navigator(".navi");

	// when page loads setup keyboard focus on the first horzontal scrollable
	horizontal.eq(0).scrollable().focus();

	$.fn.servicesViews = function() {

		var obj = $(this);

		$(this).each(function(index) {

			var obj = $(this);
			var objBlock = $(".service-projects",obj);
			var objLink = $("dt span",objBlock);


			$("dl",objBlock).append("<span class='close' />");

			objLink.hover(
			function () { $(this).addClass("hover"); },
			function () { $(this).removeClass("hover"); }
			).click(function() {
				if (objBlock.hasClass("service-projects_active")){
					obj.css({"z-index" : 1000});
					objBlock.css({ "height": "auto" }).removeClass("service-projects_active");
				}else{
					$(".service-item").css({"z-index" : 1000});
					$(".service-projects_active").css({ "height": "auto" }).removeClass("service-projects_active");
					obj.css({"z-index" : 1001});
					objBlock.css({ "height": $(this).height() }).addClass("service-projects_active");
					$(document).bind('click', dialogBlur);
				}
			});
			$(".close",objBlock).click(function() {
				obj.css({"z-index" : 1000});
				objBlock.css({ "height": "auto" }).removeClass("service-projects_active");
			});

			var dialogBlur = function(event){

				var target = $(event.target);
				if (target.is(".service-projects_active") || target.parents(".service-projects_active").length) {
					return;
				}
				$(".service-item").css({"z-index" : 1000});
				$(".service-projects_active").css({ "height": "auto" }).removeClass("service-projects_active");
				$(document).unbind('click', dialogBlur);

			}

			if(obj.hasClass("service-item_active")){
				obj.append("<div class='service-item_anime'></div>");
				$(".service-item_anime",obj).css({
				"width" : obj.width(),
				"height" : obj.height(),
				opacity : 0
				}).animate({opacity:1}, 7200, "easeOut")
			}

		});

	};
	$(".service-item").servicesViews();


	$.fn.equalHeight = function() {

		var obj = $(this);
		var objS = $(".sidebar",obj);

		if (obj.height()>objS.height()){
			$(".br_m", objS).height(obj.height() - 4);
		}

	};
	$(".columns").equalHeight();


	

	
	$.fn.LoadContent = function(activeHref, isLoad) {

		var obj = $(this);
		var objNav = $(".load-nav",obj);
		var objCont = $(".load-cont",obj);
		
			
		$.fn.setActiveContent = function(isLoad){
				
					$("a.active",objNav).removeClass("active");
			    	$(this).addClass("active");
			    	if(!isLoad){
			    	objCont.load($(this).attr("href"));
			    	}
				};

		$("a",objNav).click( function(e) {
			e.preventDefault();
			$(this).setActiveContent();	
		});
		
		
		if(!activeHref){
		$("a:first",objNav).setActiveContent();
		}else{
		$('a[href$="' + activeHref + '"]',objNav).setActiveContent(isLoad);
		}
	
	};
	
	





});
