﻿	var flagChooseCity = false;
$(document).ready(function() {
	$(".p-menu li").hover(function(){
		$(this).addClass("hovered");
	}, function(){
		$(this).removeClass("hovered");
	});
	
	formValidate();
	/*
	$(".clients > span > img").each(function(){
		var half = parseInt($(this).width()/2);
		$(this).css("margin-left","-"+half+"px");
	});
*/
	$(".clients").find("span > img.black").mouseenter(function(){
		$(this).css("display","none");
		$(this).parent().find(".white").css("display","inline");
	});
	
	$(".clients").find("span > img.white").mouseleave(function(){
		$(this).css("display","none");
		$(this).parent().find(".black").css("display","inline");

	});

	$("#selector > span").click(function(){
		/* $(this).html("Все работы &darr;"); */
		$(".selector").fadeIn("fast", function () {
			flagChooseCity=true;
		});
	});
	
	$(".b-lastw > ul > li[class!=clear]").each(function(){
		var ind = $(".b-lastw > ul > li[class!=clear]").index(this);
		if(ind % 3 == 0 && ind!=0){
			$(this).before('<li id="'+ind+'" class="clear">&nbsp;</li>');			
		}
	});
	
	var current_date = new Date();
	$("#year").html(current_date.getFullYear());

});

function formValidate(){
	$('#c-form').validate();
}

function showPopup(iClass){
	var popup = $(".iClass").dropShadow();
	var h = parseInt($(document).height());
	var hPopup = parseInt($("."+iClass).height()/2);
	$("body").prepend("<div onclick='closePopup()' id='darkhole' style='height:" + parseInt(h + hPopup) + "px'></div>");
	$("."+iClass).css("display","block").css("top",parseInt(getClientCenterY()) + "px");
}

function getyScroll(){yScroll = 0;if (window.innerHeight && window.scrollMaxY || window.innerWidth && window.scrollMaxX){yScroll = window.innerHeight + window.scrollMaxY;xScroll = window.innerWidth + window.scrollMaxX;var deff = document.documentElement;var wff = (deff&&deff.clientWidth) || document.body.clientWidth || window.innerWidth || self.innerWidth;var hff = (deff&&deff.clientHeight) || document.body.clientHeight || window.innerHeight || self.innerHeight;xScroll -= (window.innerWidth - wff);yScroll -= (window.innerHeight - hff);} else if (document.body.scrollHeight > document.body.offsetHeight || document.body.scrollWidth > document.body.offsetWidth){yScroll = document.body.scrollHeight;xScroll = document.body.scrollWidth;}else{yScroll = document.body.offsetHeight;xScroll = document.body.offsetWidth;}return yScroll;}
function getBodyScrollTop(){return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);}
function getClientHeight(){return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;}
function getClientCenterY(){return parseInt(getClientHeight()/2)+getBodyScrollTop()-250;}


function closePopup() {
	$("#darkhole").remove();
	$(".popup").css("display","none");
}

$(document).bind('click keydown', function(e) {
	if (flagChooseCity == true) {
		e=window.event||e;
		var element=e.target||e.srcElement;

		if(e.keyCode==27 || $(element).parent().attr("id")!='selector'){
			$(".selector").fadeOut("fast");
			/* $("#selector > span").html("Все работы &rarr;"); */
			flagChooseCity=false;
		}
	}
});
