$(document).ready(function(){
	// Обновить информацию о корзине
	showBasket();

	$(".showerFabricList").click(function(event){
		var elem = $(event.target);
		var idNom = elem.attr("idNom");
		if($("#fabricList"+idNom).css("display")=="none"){
			$("#fabricList"+idNom).animate({height: 'show'}, 400);
		}else{
			$("#fabricList"+idNom).animate({height: 'hide'}, 400);
		}

	 	return false;
	})


	$(".showerCidList").click(function(event){
		var elem = $(event.target);
		var idNom = elem.attr("idNom");
		if($("#cidList"+idNom).css("display")=="none"){
			$("#cidList"+idNom).animate({height: 'show'}, 400);
		}else{
			$("#cidList"+idNom).animate({height: 'hide'}, 400);
		}
	 	return false;
	})


/*	$('#showerAlphabet').click(function(event){
		if($("#alphabetList").css("display")=="none"){
			$("#alphabetList").animate({height: 'show'}, 400);
		}else{
			$("#alphabetList").animate({height: 'hide'}, 400);
		}
		return false;		
	});*/

	$('#showerAlphabet').click(function(event){
		if($("#lineList").css("display")=="block"){
			$("#lineList").animate({height: 'hide'}, 400);
		}else{
			$("#lineList").animate({height: 'show'}, 400);
		}
		return false;		
	});

	$('#countryChanger').click(function(event){
		if($("#countryList").css("display")=="none"){
			$("#countryList").animate({height: 'show'}, 400);
		}else{
			$("#countryList").animate({height: 'hide'}, 400);
		}
		return false;
	});
});


	// Добавление в корзину
	function toBasket(idNom,s){
//	$(".bay,.bayToo").click(function(event){
//		var elem = $(event.target);
		var elem = $("#bay"+idNom+s);
//		var idNom = elem.attr("idNom");
//		var idNom = $(this).attr("idNom")
		$.post("/7/",{id: idNom,count: s=="s"?$("#count").attr("value"):1},function(data){
			if(data=="adding"){
//				$("#adding"+idNom+s).css("left",elem.offset().left - 30).css("top",elem.offset().top).show();
				$("#adding"+idNom+s).fadeIn(300);
			}else if(data=="earlier_add"){
//				$("#earlier_add"+idNom+s).css("left",elem.offset().left - 50).css("top",elem.offset().top).show();
				$("#earlier_add"+idNom+s).fadeIn(300);
			}
			showBasket();
			setTimeout(
				function ShowToolTip(event){	
					$("#adding"+idNom+s).fadeOut(400);
					$("#earlier_add"+idNom+s).fadeOut(400);
				}
			, 1500);
			
		});
		return false;
	}
//	);

function updateBasket(){
	var countsumm = 0;
	$(".inputCount").each(
		function(n,element){
			var idNom = element.name.substr(5);
			var unit = $("#unit_id"+idNom).attr("value");

			if(unit=='1'){
				var value = parseInt(element.value);
				element.value = value;
			}else{
				var value = parseFloat(element.value.replace(",", "."));
				value = Math.round(value*1000)/1000;
				element.value = value;
			}

			var price = parseFloat($("#price"+idNom).html());

			if(value>0){
				currentSumm = Math.round(price*value*100)/100;
				$("#totalPriceTovar"+idNom).html(currentSumm);
				countsumm += currentSumm;
			}else{
				element.value = 0;
				$("#totalPriceTovar"+idNom).html(0);
			}
		}
	);
	$("#countsumm").html(countsumm);
}

function showBasket(){
	$(".order",top.document).load("/7/view/1/");
}

function ShowMessage(s){ 
	if(s!=''){
	        $("#messagerWindow #ms").html(s);
	        $("#messagerWindow")
			.css("display","block")
			.css("height",(document.getElementById("page").offsetHeight)+"px");

		$("#messagerWindow .messagerFront")
			.css("top",(document.body.scrollTop+(document.body['clientHeight'] - 80)/2))
			.css("left",(document.body['clientWidth'] - 300)/2);
	}
	return false;
}
function ShowExample(src){ 
	var widthWindow = 600;
	var heightWindow = 520;

//	$("#popUpWindow #content iframe").attr("src","/templates/load.html");
	$("#popUpWindow #contentTovar").load("/templates/load.html", function(){		
		var wWindow,hWindow;
		// общий синтаксис
		if (self.innerHeight) {
		    wWindow = self.innerWidth;
		    hWindow = self.innerHeight;
		// IE 6 Strict Mode
		} else if (document.documentElement && document.documentElement.clientHeight) {
		    wWindow = document.documentElement.clientWidth;
		    hWindow = document.documentElement.clientHeight;
		// Остальные версии IE
		} else if (document.body) {
		    wWindow = document.body.clientWidth;
		    hWindow = document.body.clientHeight;
		}

		$("#popUpWindow .messagerFront")
			.css("top",($(document).scrollTop()+(hWindow -  heightWindow)/2))
			.css("left",(wWindow - widthWindow)/2);


		$("#popUpWindow").css("height",(document.getElementById("page").offsetHeight)+"px").fadeIn(400,function(){
			$("#popUpWindow #contentTovar").load(src+"?"+Math.random());
		})

	}
	);

	return false;
}

function CloseExample(){
	$('#popUpWindow',window.parent.document).hide();
	$("#popUpWindow iframe",window.parent.document).attr("src","/templates/load.html");
	return false;
}
function setRadingFormOrder(){
	$("#formaOrder").validate({		
               rules : {
                	name : {required : true, minlength: 6}
			,phone: {required: true, minlength: 6}
			,email: {required: true, email: true}
               },
               messages : {
                       	name : {
                               required : "Введите ваше имя",
                               minlength : "Введите не менее, чем 6 символа"
	                      }
                       	,phone : {
                               required : "Введите номер контактного телефона",
                               minlength : "Введите не менее, чем 6 символа"
	                      }
			,email: {
                                required : "Введите адрес электронной почты",
				email: "Нужен корректный email адрес"
	                      }
	       }

       });
}

