// ------------------------------------------- Valoo ------------------------------------------------------------------- //
selectRedirect = function (select_id, get_id, page){
	$(select_id).change(
		function(){
			id = $(this).find("option:selected").attr("value");
			window.location = page+"?"+get_id+"="+id;
		}
	);
}
// --------------------------------------------------------------------------------------------------------------------- //

$(document).ready(function(){
        $('div.news_body').hide();
		//$('p.active').next('tr.news_body').show();
		//$('p.active').find('a').toggleClass("selected");
        $('h2.p_link').click(function(){
			$(this).toggleClass("selected");
			$(this).next('div.news_body').toggle('fast');
		});
        $('h2.p_link2').click(function(){
			$(this).toggleClass("selected");
			$(this).next('div.news_body').toggle('fast');
		});
        $('h2.p_link3').click(function(){
			var v=$(this).attr("rel");
			if ( $(this).next('div.news_body').css("display") === 'block' ){
			$(this).next('div.news_body').toggle('fast');
			}else{
			$('div.news_body').hide();
			$(this).toggleClass("selected");
			$(this).next('div.news_body').toggle('fast');
			$('#zapch_img').find('img').attr("src","/include/images/photo/"+v+"_small.jpg");
			$('#zapch_img').find('a').attr("href","/getphoto/?href="+v+"&title=");
			/*if (v=="065") {
			$('#zapch_img').html('<a onclick="window.open(this.href, \''+v+'\', \'width=600, height=400 ,status=no, toolbar=no, menubar=no, scrollbars=no\');return false;" target="055" href="/getphoto/?href='+v+'&amp;title="><img height="328" width="334" title="Кабина" alt="Кабина" class="" src="/include/images/photo/'+v+'_small.jpg"></a><a onclick="window.open(this.href, \''+v+'\', \'width=600, height=400 ,status=no, toolbar=no, menubar=no, scrollbars=no\');return false;" target="055" href="/getphoto/?href='+v+'a&amp;title="><img height="328" width="334" title="Кабина" alt="Кабина" class="" src="/include/images/photo/'+v+'a_small.jpg"></a><a onclick="window.open(this.href, \''+v+'\', \'width=600, height=400 ,status=no, toolbar=no, menubar=no, scrollbars=no\');return false;" target="055" href="/getphoto/?href='+v+'b&amp;title="><img height="328" width="334" title="Кабина" alt="Кабина" class="" src="/include/images/photo/'+v+'b_small.jpg"></a><a onclick="window.open(this.href, \''+v+'\', \'width=600, height=400 ,status=no, toolbar=no, menubar=no, scrollbars=no\');return false;" target="055" href="/getphoto/?href='+v+'c&amp;title="><img height="328" width="334" title="Кабина" alt="Кабина" class="" src="/include/images/photo/'+v+'c_small.jpg"></a><a onclick="window.open(this.href, \''+v+'\', \'width=600, height=400 ,status=no, toolbar=no, menubar=no, scrollbars=no\');return false;" target="055" href="/getphoto/?href='+v+'d&amp;title="><img height="328" width="334" title="Кабина" alt="Кабина" class="" src="/include/images/photo/'+v+'d_small.jpg"></a>')
			}
			else{
			$('#zapch_img').html('<a onclick="window.open(this.href, \''+v+'\', \'width=600, height=400 ,status=no, toolbar=no, menubar=no, scrollbars=no\');return false;" target="055" href="/getphoto/?href='+v+'&amp;title="><img height="328" width="334" title="Кабина" alt="Кабина" class="" src="/include/images/photo/'+v+'_small.jpg"></a>')
			}*/
			}
			
			//$('div.news_body').hide();
			//$('#zapch_img').find('img').fadeOut();
			//$('#zapch_img').find('img').fadeIn();
			/*if ($('div.news_body').css("display") === 'block' )){
			alert (1);
			}*/
		});
		$("a.form_event").click(
			function(){

				$("#overlay_order").show();
				$('#BlockOrder').show();
				}
		);

		$("#close").click(
			function(){
				$("#overlay_order").hide();
				$('#BlockOrder').hide();
				}
		);
		
// ------------------------------------------- Valoo ------------------------------------------------------------------- //
		// District select
		selectRedirect('#district', 'district_id', '/service/')
		selectRedirect('#district_were', 'district_id', '/where/')
		
		/*$(".covered .main_tbl").hide();
		$("h2.cover").click(
			function(){
				$(this).next(".main_tbl").slideToggle("fast");
			}
		);*/
		
		$("#service_popup").click(
			function(){
				$("#popup").show();
			}
		);
		$(".popup-close, #opacity").click(
			function(){
				$("#popup").hide();
			}
		);
		
		
		function defPosition(event) {
		    var x = y = 0;
		    if (document.attachEvent != null) { // Internet Explorer & Opera
		        x = window.event.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
		        y = window.event.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
		    } else if (!document.attachEvent && document.addEventListener) { // Gecko
		        x = event.clientX + window.scrollX;
		        y = event.clientY + window.scrollY;
		    } else {
		        // Do nothing
		    }
		    return {x:x, y:y};
		}
		
		$(".slider_top_outer .prev").mouseover(function(event){
		var event = event || window.event;
		//alert(defPosition(event).y);
		var v=$(this).attr("rel");
		$('#podskazka').css('left',defPosition(event).x+10);
		$('#podskazka').css('top',defPosition(event).y+10);
		$('#podskazka').attr("src","/include/images/preview/"+v+".jpg");
		$('#podskazka').show();
		});
		$(".slider_top_outer .prev").mouseout(function(){
		$('#podskazka').hide();
		});
		
		$(".slider_top_outer .next").mouseover(function(event){
		var event = event || window.event;
		//alert(defPosition(event).y);
		var v=$(this).attr("rel");
		$('#podskazka').css('left',defPosition(event).x-168);
		$('#podskazka').css('top',defPosition(event).y+20);
		$('#podskazka').attr("src","/include/images/preview/"+v+".jpg");
		$('#podskazka').show();
		});
		$(".slider_top_outer .next").mouseout(function(){
		$('#podskazka').hide();
		});
		
		
		
		$("UL.toggleMenu LI.toggleClose P").hide();
	$("UL.toggleMenu SPAN.headIssue").click(function(){
		var i=0;
		var elemP1 = this.parentNode;
		if ( this.parentNode.className == 'toggleClose' ){
			this.parentNode.className = 'toggleOpen';
			while ( elemP1.childNodes.length > i ){
				if (elemP1.childNodes[i].tagName == "P"){
					$(elemP1.childNodes[i]).show(150);
				}
				i++;
			}
		}else{
			this.parentNode.className = 'toggleClose';
			while ( elemP1.childNodes.length > i ){
				if (elemP1.childNodes[i].tagName == "P"){
					$(elemP1.childNodes[i]).hide(150);
				}
				i++;
			}
		}
	});
// --------------------------------------------------------------------------------------------------------------------- //
});
