$(document).ready(function() {
	
	$("a#auth").click(function() {
		$(".form-wrap .form").css("top", "2px");
	});	
	
	$(".form a.close").click(function() {
		$(this).parent().css("top", "-10000px");
	});

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////video main page
	$(".video a, #view_video").bind("mouseover", function(){
			$(".video .play").show();
			
			return false;
	});
	
	$(".video a, #view_video").bind("mouseout", function(){
			$(".video .play").hide();
			return false;
	});	
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////	
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////print page
	$(".print").live("click", function(){
		$("#container>#content>.index-center, #container>#content>.inner-right").clone()
								.find(".feedback").remove().end()
								.find(".print").remove().end()
								.find(".contacts-feedback").remove().end()
								.printElement();
		
		
		//alert($("#container>#content>.index-center, #container>#content>.inner-right").length);
		return false;
	});
	


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	$("a.vacancy-name").click(function() {
		$(this).toggleClass("dotted");
		$(this).parent().find(".vacancy-desc").slideToggle();
		return false;
	});
	
	$("a.certificate-name").click(function() {
		$(this).toggleClass("dotted");
		$(this).parent().find(".certificates-wrap").slideToggle();
		return false;
	});	
	
	$("a#show-question-form").click(function() {
		$(".ask-form").toggle();
		return false;
	});	
	
	$("a#hide").click(function() {
		$(".ask-form").toggle();
		return false;
	});	
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////icons	

	$(".icons li").hover(
		function() {
			$(this).find(".popup").show();
						
		},
		function() {
			$(this).find(".popup").hide();
		}
	);		
	
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////Calculator

	$("form.calc p.top a").click(function(){
				
		$(".form_pattern:first").clone().find("a.icon").show().end().find(".text").val("").end().insertAfter(".form_pattern:last");
		
		return false;
	
	});
	
//plus

	$("#plus").click(function(){
	
		var tempr = $("input[name='temperature']").val();
		//alert(tempr);
		tempr = parseInt(tempr) + 1;
		$("input[name='temperature']").val(tempr);
		
		return false;
	});
	
//minus
	$("#minus").click(function(){
	
		var tempr = $("input[name='temperature']").val();
		//alert(tempr);
		tempr = parseInt(tempr) - 1;
		$("input[name='temperature']").val(tempr);
		
		return false;
	});

//switching
	$("form.calc input[name='rooms']").click(function(){
			
			var id = $(this).val();
			//alert(id);
			
			$(".just_to_select_all").css("display", "none");
			$(".just_to_select_all input[type='radio']").each(function(){ this.checked=false; });
			$("#"+id).css("display", "block");
			
	
	});
	
//feeling hidden fields
	$("select[name='izol'] option").click(function(){
	
			$("input[name='izol_name']").val($(this).text());
		
	});
	$(".form_pattern select option").live("click", function(){
		
			$(this).parent().parent().find("input[type='hidden']").val($(this).text());
		
	});
	
//delete button
	$("form.calc .form_pattern a.icon").live("click", function(){
		
		$(this).parent().remove();
		return false;
	
	});
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////top slideshow

		var i=1;
		var resp;
		var len;
		var during = "3s";	
		
		
		$.ajax({
					
				url: "/bitrix/templates/main/slideshow_top.php",
				type: "POST",
				dataType: "json",
				
				success: function(response){
					
					$(".head div.image img").attr("src", response.files[0] );
					len = response.files.length;
					resp = response;
					
					
				},
						
				error: function(XMLHttpRequest, textStatus, errorThrown) {
								
					alert(textStatus);
				}
		});
		
		
		$(".head div.image img").everyTime(during, "timer1", function(){	
						
						$(".head div.image img").attr("src", resp.files[i++] );
						$(".head .inner-right li.active").removeClass("active");
						$(".head .inner-right li a[n='" + i + "']").parent().addClass("active");
						
						if(i>len-1) i=0;
						
		},0);
			
		
		$(".head .inner-right li a").click(function(){
			
			i = parseInt( $(this).text() )-1;
			$(this).parent().parent().find(".active").removeClass("active");
			$(this).parent().addClass("active");
			$(".head div.image img").attr("src", resp.files[i] );
			
			
			$(".head div.image img").stopTime("timer1");
			$(".head div.image img").everyTime(during, "timer1", function(){
						
						
						$(".head div.image img").attr("src", resp.files[i++] );
						$(".head .inner-right li.active").removeClass("active");
						$(".head .inner-right li a[n='" + i + "']").parent().addClass("active");
						
						if(i>len-1) i=0;
						
			},0);
			
			
			return false;
			
		});
		
		$(".head .inner-right a.previous").click(function(){
			var item = parseInt($(".inner-right li.active a").attr("n"))-1;
			
			if( item == 0 ) i = 6;
			else i = item-1;
			$(".head .inner-right li.active").removeClass("active");
			$(".head .inner-right li a[n='" + (i+1) + "']").parent().addClass("active");
			$(".head div.image img").attr("src", resp.files[i++] );
			
			
			$(".head div.image img").stopTime("timer1");
			$(".head div.image img").everyTime(during, "timer1", function(){
						
						
						$(".head div.image img").attr("src", resp.files[i++] );
						$(".head .inner-right li.active").removeClass("active");
						$(".head .inner-right li a[n='" + i + "']").parent().addClass("active");
						
						if(i>len-1) i=0;
						
			},0);
			
			return false;
		});
		
		
		$(".head .inner-right a.next").click(function(){
			var item = parseInt($(".inner-right li.active a").attr("n"))-1;
			
			if( item == 6 ) i = 0;
			else i = item+1;
			$(".head .inner-right li.active").removeClass("active");
			$(".head .inner-right li a[n='" + (i+1) + "']").parent().addClass("active");
			$(".head div.image img").attr("src", resp.files[i++] );
			
			
			$(".head div.image img").stopTime("timer1");
			$(".head div.image img").everyTime(during, "timer1", function(){
						
						
						$(".head div.image img").attr("src", resp.files[i++] );
						$(".head .inner-right li.active").removeClass("active");
						$(".head .inner-right li a[n='" + i + "']").parent().addClass("active");
						
						if(i>len-1) i=0;
						
			},0);
			
			return false;
		});
		
		
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////app slideshow main page

		var i2=1;
		var resp2;
		var len2;
		var during2 = "3s";	
		
		
		$.ajax({
					
				url: "/bitrix/templates/main/slideshow_app.php",
				type: "POST",
				dataType: "json",
				
				success: function(response){
					
					$(".index-left .slideshow a img").attr("src", response.files[0]['src'] );
					$(".index-left .slideshow .name").text( response.files[0]['name'] );
					len2 = response.files.length;
					resp2 = response;
				
					
				},
						
				error: function(XMLHttpRequest, textStatus, errorThrown) {
								
					alert(textStatus);
				}
		});
		
		
		$(".slideshow a.play").css("background","url(/bitrix/templates/main/images/play.png) right top no-repeat");
		
		$(".index-left .slideshow a img").everyTime(during2, "timer2", function(){	
						
						$(this).attr("src", resp2.files[i]['src'] );						
						$(this).parent().parent().find(".name").text(resp2.files[i]['name']);
						i++;
						if(i>len2-1) i=0;
						
		},0);
		
		$(".slideshow .pause").click(function(){			
			$(".index-left .slideshow a img").stopTime("timer2");	
			
			//pause
			$(".slideshow a.pause").unbind("mouseout mouseover");
			$(".slideshow a.pause").css("background","url(/bitrix/templates/main/images/pause.png) right top no-repeat");
			
			
			//play
			$(".slideshow a.play").css("background","url(/bitrix/templates/main/images/play.png) left top no-repeat");
						
			$(".slideshow a.play").bind("mouseover", function(){
				$(".slideshow a.play").css("background","url(/bitrix/templates/main/images/play.png) right top no-repeat");
			});
			$(".slideshow a.play").bind("mouseout", function(){
				$(".slideshow a.play").css("background","url(/bitrix/templates/main/images/play.png) left top no-repeat");
			});
			
			return false;			
		});
		
		$(".slideshow .play").click(function(){		
		
			$(".index-left .slideshow a img").everyTime(during2, "timer2", function(){	
						
						$(this).attr("src", resp2.files[i]['src'] );						
						$(this).parent().parent().find(".name").text(resp2.files[i]['name']);
						i++;
						if(i>len2-1) i=0;
						
			},0);
			
			//pause
			$(".slideshow a.pause").css("background","url(/bitrix/templates/main/images/pause.png) left top no-repeat");
			$(".slideshow a.pause").bind("mouseover", function(){
				$(".slideshow a.pause").css("background","url(/bitrix/templates/main/images/pause.png) right top no-repeat");
			});
			$(".slideshow a.pause").bind("mouseout", function(){
				$(".slideshow a.pause").css("background","url(/bitrix/templates/main/images/pause.png) left top no-repeat");
			});
			
			//play
			$(".slideshow a.play").unbind("mouseout mouseover");
			$(".slideshow a.play").css("background","url(/bitrix/templates/main/images/play.png) right top no-repeat");
			
			
			return false;
		});
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////certifates preview
		 $(function() {
			$('.certificates-block a.certificate').lightBox({
			txtImage: ""
			});
		 });
		 
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////click to search form
		
		$("#footer .search div.float input[name='q']").click(function(){		
				if( $(this).val()=="Поиск по сайту" ) $(this).val("");	
				
				$("body").not("input").click( function(){		
					if( $("#footer .search div.float input[name='q']").val()=="" ) $("#footer .search div.float input[name='q']").val("Поиск по сайту");
					//$(this).unbind("click");
				});
				return false;
		});
		
		
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////map
	
	$("div.map div.pick_1").click(function(){			
			$(this).parent().find("img").hide().end()
					.find("#scheme1").show().end()
					.find(".picker").hide().end()
					.find(".back").show().end()
					.find("span").hide().end()
					.find(".text_scheme_1").show();	
	});
	$("div.map div.pick_2").click(function(){			
			$(this).parent().find("img").hide().end()
					.find("#scheme3").show().end()
					.find(".picker").hide().end()
					.find(".back").show().end()
					.find("span").hide().end()
					.find(".text_scheme_3").show();	;	
	});
	$("div.map div.pick_3").click(function(){			
			$(this).parent().find("img").hide().end()
					.find("#scheme2").show().end()
					.find(".picker").hide().end()
					.find(".back").show().end()
					.find("span").hide().end()
					.find(".text_scheme_2").show();	;	
	});	
	$("div.map div.back").click(function(){			
			$(this).parent().find("img").hide().end()
					.find("#district").show().end()
					.find(".picker").show().end()
					.find(".back").hide().end()
					.find("span").hide();	
	});	
	//////text click
	$("div.map span a.text_pointer_e").click(function(){
		$("div.map div.pick_2").click();
		return false;
	});
	$("div.map span a.text_pointer_b").click(function(){
		$("div.map div.pick_3").click();
		return false;
	});
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
});
