var ie = 0/*@cc_on+@_jscript_version*10@*/; 
var is_expanding_l = true;
var is_expanding_r = true;

var is_not_expanding = false;

var main_linklock_h = 0;
var main_linklock_endh = 0;

var promo_focus = false;

var is_oldopera = false;

var old_w = 0;
var old_h = 0;

$(document).ready(function()
{

	/*Контент на главной*/
	$(".index-content .slide").not(":first").css("display","none");
	$(".index-content .slide:first").addClass("visible");
	setInterval('change_slide()', 15000);
	
	/*\\Контент на главной*/

	var ie = 0/*@cc_on+@_jscript_version*10@*/; 
	if (($.browser.msie) && (jQuery.browser.version=="6.0")) { ie = 56 }
	
	if (ie==56)
	{
		if (getCookie('oldbrowser')!='skip')
		{
			$('#index').prepend('<p class="old-browser">Ваш браузер морально устарел'+
				' рекомендуем установить более современные браузеры: <a href="http://www.opera.com/download/get.pl?id=33087&thanks=true&sub=true">Opera</a>'+
				' <a href="http://www.google.ru/chrome?hl=ru&brand=CHMI">Chrome</a>'+
				'<br/><u>закрыть и больше не показывать</u>');
		}
		
		$('.old-browser u').click(function(){
			setCookie('oldbrowser','skip');
			$('.old-browser').remove();
		});
	}			
	
	// при первом заходе на сайт невыбирает регион, т.к. кука ставится после серверного 
	// алгоритма выбора региона
		if ($("#city-list .active").length==0)
		{
			var reg_ = getCookie("BITRIX_SM_region");
			$("#city-list a[id='"+reg_+"']").parent().addClass("active");
		}
		$("#city-list #426,#city-list #471,#city-list #472").css("font-size","17px");
		
		if ($("#YMapsID2").length>0)
		{
			$(".splash-r").css("margin-left",0);
			$("#index.c .splash-r .text .left").css("margin-top",0);
		}
		
		// список городов
		var citylist_timer=0;
		$("#city-list").hover(
		function(){
			if (citylist_timer>0)
			{
				clearTimeout(citylist_timer);
				citylist_timer=0;
			}
		},
		function()
		{		
			citylist_timer = setTimeout(citylist_hide,500);
		});
		function citylist_hide()
		{
			citylist_timer=0;
			$("#city-list div:not(.active)").hide();
			$("#city-list .active").css("padding-bottom","3px");
		}
		
		// список выбора города
		$("#city-list a").click(function()
		{
			if ($(this).parent().attr("class")!="active")
			{
				prev_text = $("#city-list div.active a").html();
				
				title_ = window.document.title;			
				window.document.title = title_.replace(new RegExp(prev_text,'g'),$(this).html());
				
				$("#city-list div").css("padding-bottom","8px");
				$("#city-list div.active").removeClass("active");
				$(this).parent().addClass("active");
				$("#city-list div:not(.active)").hide();

	//			$("#city-list .active").css("padding-bottom","3px");			
				$("#city-list .active").css("padding-bottom","8px");
				
				setCookie("BITRIX_SM_region",$(this).attr("id"));
				
				if ($("#YMapsID").length>0)
				{
					var coord = $(this).attr("class")
					coordxy = coord.split(",");
					var point = new YMaps.GeoPoint();	
					point.setLat(parseFloat (coordxy[1]));
					point.setLng(parseFloat (coordxy[0]));
					
					map.panTo(point,{flying: 1});
				}			
			}
			else
			{
				$("#city-list div").show();
				$("#city-list .active").css("padding-bottom","8px");
			}
			return false;
		});
	
	if (ie!=56)
	{
		//фикс
		if ($(".accordion-2 dd .line-one").length>0)
		{
			for (i=0;i<$(".accordion-2 dd .line-one").length;i++)
				$(".accordion-2 dd:eq("+i+") .line-one:first").css("margin-top","16px");
		}
		// фикс
		$("#index.a .splash-r .first-elem .auth .text-input:last").append("<span>Пароль</span>");
		$("#index.a .splash-r .first-elem .auth .text-input:last input").attr("value","");
		$("#index.a .splash-r .first-elem .auth .text-input:last input").attr("rel","");
		// фикс
		$("#index.c .form-auth .form-elem:eq(1)").append("<span>Пароль</span>");
		$("#index.c .form-auth .form-elem:eq(1) input").attr("value","");
		$("#index.c .form-auth .form-elem:eq(1) span").click(function()
		{
			$(this).hide();
		});
		$("#index.c .form-auth .form-elem:eq(1) input").focus(function()
		{
			if ($(this).get(0).value=='')
				$("#index.c .form-auth .form-elem:eq(1) span").hide();
		});
		$("#index.c .form-auth .form-elem:eq(1) input").blur(function()
		{
			if ($(this).get(0).value=='')
				$("#index.c .form-auth .form-elem:eq(1) span").show();
		});
		
		$("#index.b .promo-elems .elem:first").addClass("first");
		$("#index .promo-elems .elem sub").animate({opacity: 0},1);

		if ($("#sert-wrapper").length!=0) $("#sert-wrapper").remove();
		$("#index").prepend("<div id='sert-wrapper'><div class='spinner'></div><div class='blend'></div><div class='picture'></div></div>"); 
		$("#index").prepend("<div id='tooltip'><b></b><p></p></div>");
		
		$("#index.a .splash-l .link-block small").animate({opacity: 0},1);

		// what is browser  ??
		if (($.browser.msie) && (jQuery.browser.version=="6.0")) { ie = 56 }
		is_oldopera = ($.browser.opera && (($.browser.version=='9.23') || ($.browser.version=='9.24')));

		if (!$.browser.msie)
			$("#sert-wrapper").animate({opacity: 0},1);
		
		//set_all_size();
		timer_id = setTimeout(set_all_size, 200);	
		main_page();				

		$(window).resize(function()
		{
			if ((old_w!=document.getElementsByTagName('html')[0].clientWidth) || 
					(old_h!=document.getElementsByTagName('html')[0].clientHeight))
			{
				old_w=document.getElementsByTagName('html')[0].clientWidth;
				old_h=document.getElementsByTagName('html')[0].clientHeight;

				set_all_size();
			}
		});	
		
		
		// промоблоки и баннеры
		$("#index.a .promo-elems a:last,#index.b .promo-elems a:last").not('.page').click(function(){
			is_not_expanding = true;
			var pth_ = $(this).attr("href");
			
			if (pth_!='') {				
				$("#sert-wrapper").addClass("loaded");
				$("#sert-wrapper .picture").html('<img src="'+pth_+'"/><strong class="slogan">Детское окно по специальной цене!</strong>');
				//$("#sert-wrapper .picture a").attr("href","img.php?file="+pth_);
				if (!$.browser.msie)
//					$("#sert-wrapper").css('filter','alpha(opacity=100)').show();
//				else
					$("#sert-wrapper").animate({opacity: 1},250);

				$("#sert-wrapper .blend").css("display","block");
				$("#sert-wrapper").css("left","0");
				var h_ = $("#sert-wrapper img").height();
				if (h_>50) 
				{
					showjpg();
				}
				else
				{
					$("#sert-wrapper img").load(function()
					{
						showjpg();
					});
				}
			}
			return false;

			
			
		});
		$("#index.a .promo-elems a:first,#index.b .promo-elems a:first").click(function()
		{
			is_not_expanding = true;

			var pth_ = $(this).attr("href");
			if (pth_!='')
			{				
				$("#sert-wrapper").addClass("loaded");
				$("#sert-wrapper .picture").html("<img src='"+pth_+"'/><a href='#печатать'>распечатать</a>");
				//$("#sert-wrapper .picture a").attr("href","img.php?file="+pth_);
				if (!$.browser.msie)
//					$("#sert-wrapper").css('filter','alpha(opacity=100)').show();
//				else
					$("#sert-wrapper").animate({opacity: 1},250);

				$("#sert-wrapper .blend").css("display","block");
				$("#sert-wrapper").css("left","0");
				var h_ = $("#sert-wrapper img").height();
				if (h_>50) 
				{
					showjpg();
				}
				else
				{
					$("#sert-wrapper img").load(function()
					{
						showjpg();
					});
				}
			}
			return false;
		});
		$("#sert-wrapper .picture a").live("click",function()
		{
			/*var pht = $(this).attr("href");
			var newWin = window.open(pht,'',
			"width="+$("#sert-wrapper .picture").width()+",height="+$("#sert-wrapper .picture").height()); 
			return false;*/
			if('#печатать' == $(this).attr('href')){
				window.print();
				return false;
			} else {
				return true;
			}
		});
		$("#sert-wrapper").click(function()
		{		
			if ($("#sert-wrapper form").length==0)
			{
				popup_unload();
			}
		});
		$("#sert-wrapper .blend").click(function()
		{
				popup_unload();
		});
		
			
		// аккордеоны
		var flag = true;
		$(".accordion dt").hover(function()
		{
			$(this).addClass("hovered");
		},
		function()
		{
			$(this).removeClass("hovered");
		});
		$(".accordion dt").click(function()
		{

								var o = $(this).parent().find("dd");
								
								var p_obj = $(".accordion dd.expanded");
								p_obj.animate({height: 0},200,function()
								{
									p_obj.removeClass("expanded");
								});

								if ((o.attr("class")!="expanded") && (flag))
								{
									flag = false;
									var h_ = o.get(0).scrollHeight - o.get(0).clientHeight;// + o.find("dt").height();
									
									o.animate({height: h_},200,function()
									{
										
										o.height(h_);
										o.addClass("expanded");
										flag = true;
									});
								}
		});	
		
		// тултипы
		$("#tooltip b").click(function()
		{
			$("#tooltip").hide();
		});
		$(".tooltip").click(function(e)
		{
			var res_ = mousePageXY_(e);		
			$("#tooltip p").html($(this).find("b").html());
				
				$("#tooltip").css("left",res_[0]+16+'px');
				$("#tooltip").css("top",res_[1]+10+'px');
				$("#tooltip").show();
		});
	} // if ie6
	inner_page();
});

//Смена слайдов на главной
function change_slide(){
	$(".index-content .slide.visible")
		.fadeOut('slow', function(){
			$(this).removeClass("visible")
			$nextSlide = $(this).next();
			if(!$nextSlide.html()){
				$nextSlide = $(".index-content .slide:first");
			}
			$nextSlide
				.fadeIn('slow', function(){
					$nextSlide.addClass("visible");
					//change_slide();
				})				
		})
}
//\\Смена слайдов на главной

function showjpg()
{
		var h_ = $("#sert-wrapper img").height();
		var w_ = $("#sert-wrapper img").width();
		ch_ =  !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
		if (h_>ch_) 
		{			
			w_ = w_*(0.8*ch_)/h_;
			h_ = 0.8*ch_;
			$("#sert-wrapper img").width(w_);
			$("#sert-wrapper img").height(h_);
		}

		// свистелки и перделки
		$("#sert-wrapper .spinner").css("background-image","none");
		$("#sert-wrapper .spinner").animate({width: w_,height: h_,
		marginTop: -h_/2,marginLeft: -w_/2,opacity: 0},150,function()
		{
			if (ie==56)
				$("#sert-wrapper .picture").animate({opacity: 1},1);

			$("#sert-wrapper .picture").css("margin",-h_/2+"px 0 0 -"+w_/2+"px");
			$("#sert-wrapper .picture").height(h_);
			$("#sert-wrapper .picture").width(w_);

			$("#sert-wrapper .picture").css("left","50%");
			$("#sert-wrapper .picture").css("cursor","default");	
			$("#sert-wrapper").removeClass("loaded");
		});
}

function set_all_size()
{
	$("#YMapsID").hide();
	
	var ch = document.getElementsByTagName('html')[0].clientHeight;	
	$("#index.a .splash .text").width($("#top").width()/2-60);
	//$("#index.b .splash .text").width($("#top").width());
	if ($(".splash-l").attr("class").indexOf('splash-l-hovered')==-1)
	{
		//$(".splash-l .text").css("left",-$("#top").width()/2+'px');
	}
	else
	{
		$("#index.a .splash-l").width($("#top").width()/2);
		$("#index.b .splash-l").width($("#top").width());
	}
	
	if ($(".splash-r").attr("class").indexOf('splash-r-hovered')==-1)
	{
		//$(".splash-r .text").css("right",-$("#top").width()/2+'px');
	}
	else
	{
		$(".splash-r").width($("#top").width()/2);
	}
	
	if (!is_oldopera)
		$(".splash,.splash .text").show();
	else
		$(".splash,.splash-l .text").show();
	//$(".splash-l .splash-img img").css("left",$(".splash-l").width()-720+'px');								

	// внутренние
	$("#index.b .splash,#index.c .splash").height(ch+'px');
	// главная - рассчет высоты блоков со ссылками слева
	var h_ = ch;
	var mh_= 0;
	if (h_<600)
	{	
		h_ = 600;
		ch = 600;
	}
	if (h_>720) 
	{
		$("#index.a .splash-l .text").css("top",(h_-770)/2+'px');
		$("#index.a .splash-r .text").css("top",(h_-700)/2+'px');
		h_ = 720;
	}
	else
	{
		$("#index.a .splash-l .text").css("top",0);
		$("#index.a .splash-r .text").css("top",0);
	}

	$("#index.a .splash").height(ch+'px');
	$("#index.a .flash-main-menu").height(h_-280);
	
	mh_ = (h_-250)/6-10;

	main_linklock_h = mh_;
	$("#index.a .splash-l .link-block").height(mh_);
	
	// позиция футера на главной
	$("#index.a .splash-l .footer").css("top",7*(mh_)+190+'px');
	
	$("#index.a .splash-l .promo-elems-wrapper").css("top",7*(mh_)+40+'px');
	
	// позиция городов
	$("#index.a #city-list").css("left",$("#top").width()/2-287+'px');
	$("#index.b #city-list").css("left",'308px');
	$("#index.c #city-list").css("left",'90px');
	
	// карусель на главной
	var carh = 2*(h_-380)/3-20;
	if (carh>160) carh = 160;
	$("#index.a .splash-r .development").height(carh-16);
	$("#index.a .splash-r .development .extra").height(carh-60);
	$("#index.a .splash-r .development .carousel").height(carh-60);
	// контакты с права на главной
	var conth = h_-380-carh;
	if (conth<80) conth=80;
	$("#index.a .splash-r .contacts").height(conth-12);
	$("#index.a .splash-r .contacts .into-into").height(conth-80);
	if (conth-70<80)
		$("#index.a .splash-r .contacts").addClass("contacts-Oh-shi-small-height");
	else
		$("#index.a .splash-r .contacts").removeClass("contacts-Oh-shi-small-height");

	// внутренняя	
	h_ = $("#index.b .splash-l .text,#index.c .splash-r .text").innerHeight();//-70;
	if (document.getElementsByTagName('html')[0].clientHeight>h_) h_ = document.getElementsByTagName('html')[0].clientHeight;
	$("#index.b .splash-l .left").height(h_-70);
	$("#index.c .splash-r .right").height(h_);
	$("#index.b .splash-r,#index.c .splash-l").height(h_);	
		
	$("#YMapsID,#YMapsID2").height(h_);
	$("#YMapsID").width($("#index.b").width()-275);
	$("#YMapsID2").width($("#index.c").width()-205);
	$("#YMapsID").show();

	//корректировка ширины правого блока на внутренних страницах
	if ($("#index.b #top").width()>1400)
	{
		//$("#index.b .splash-r").width(230);
	}
	else
	{
		//$("#index.b .splash-r").width(60);	
	}
		
}

// события главной страницы
function main_page()
{
	// карусель. превьюшки
	$(".development .extra .carousel li a").live("click",function()
	{
		is_not_expanding = true;
		var pth_ = $(this).attr("href");
		if (pth_!='')
		{				
			$("#sert-wrapper").addClass("loaded");
			$("#sert-wrapper .picture").html("<img src='"+pth_+"'/>");
			//$("#sert-wrapper .picture a").attr("href","img.php?file="+pth_);
			if ($.browser.msie)
				$("#sert-wrapper").show();
			else
				$("#sert-wrapper").animate({opacity: 1},250);

			$("#sert-wrapper .blend").css("display","block");
			$("#sert-wrapper").css("left","0");
			var h_ = $("#sert-wrapper img").height();
			if (h_>50)
			{
				showjpg();
			}
			else
			{
				$("#sert-wrapper img").load(function()
				{
					showjpg();
				});
			}
		}
		return false;
		
		return false;
	});

	// флеш ролик
	//$(".splash-r .first-elem .showvideo").click(function()
	//{
	
	//});

	// выезд элементов

	//При клике
	$("#index.a .splash").click(function(){
		if (is_not_expanding) return false;

		var splashindex;
		if($(this).hasClass('splash-l')) splashindex = 'l';
		if($(this).hasClass('splash-r')) splashindex = 'r';
		
		w_ = $("#index").width();
		
		if('l' == splashindex && is_expanding_l){
			is_expanding_l=false;
			collapse_right();
		}
			
		if('r' == splashindex && is_expanding_r){
			is_expanding_r=false;
			collapse_left();
		}
		
		if($('.splash-' + splashindex).hasClass('splash-' + splashindex + '-hovered')){
		
			if('l' == splashindex){
				collapse_left();
			}
			
			if('r' == splashindex){
				collapse_right();
			}
			
		
		} else {
		
			$('.splash-' + splashindex).addClass('splash-' + splashindex + '-hovered');
		
			if ($.browser.msie)
				$(".splash-" + splashindex).width(w_/2);
			else
				$(".splash-" + splashindex).stop().animate({width: w_/2},500);
		}
	});
	
	//отключаем скрытие шторок про клике на ссылки внутри них
	
	$(".flash-main-menu").click(function(){ 
		is_not_expanding = true;
		return true;
	});
	
	$(".splash-l a").not(".promo-elems a").click(function(){
		is_not_expanding = true;		
		if('_blank' == $(this).attr('target')){
			window.open(this.href);
			is_not_expanding = false;
			return false;
		} else{
			document.location = this.href;
		}
	});
/*	
	$("#index.a .splash .hover-title").click(function(){
		if (is_not_expanding) return false;
		if ($('.splash-l').hasClass('splash-l-hovered')) collapse_left();
		if ($(".splash-r").hasClass('splash-r-hovered')) collapse_right();
	});
*/
	
/*
	//При наведении
	$("#index.a .splash").hover(
	function(){},
	function()
	{
		if (is_not_expanding) return false;
		if ($(".splash-l").attr("class").indexOf('splash-l-hovered')>0)
		{
			collapse_left();
		}

			if ($(".splash-r").attr("class").indexOf('splash-r-hovered')>0)
			{
				collapse_right();
			}
	});	


	$("#index.a").mousemove(function(e)
	{
		if (is_not_expanding) return false;
		x_ = mousePageXY(e);
		w_ = $("#index").width();
		//левая область
		if ((x_<0.35*w_) && is_expanding_l)
		{		
			is_expanding_l=false;
			$(".splash-l").addClass("splash-l-hovered");
			
			if ($.browser.msie)
				$(".splash-l").width(w_/2);
			else
				$(".splash-l").stop().animate({width: w_/2},500);
			
			collapse_right();
		}	

		if ((x_>0.65*w_) && is_expanding_r)
		{
			is_expanding_r=false;
			$(".splash-r").addClass("splash-r-hovered");
			if ($.browser.msie)
			{
				$(".splash-r").width(w_/2);
			}
			else
			{
				$(".splash-r").stop().animate({width: w_/2},500,function()
				{
					if (is_oldopera)
						$(".splash-r .text").show();
				});
			}
			//$(".splash-r .text").stop().animate({right: 0},500);
			
			collapse_left();
		}
		
		 //document.title=;
	});
*/	
	// раскрывающиеся ссылко-блоки 
	$("#index.a .link-block").hover(function()
	{
		var this_ = $(this);
		WbrSleep(250,function()
		{
			//promo_focus = true;
			for (i=0;i<6;i++)
			{
				if ($("#index.a .link-block:eq("+i+")").attr("class")!=this_.attr("class"))
				{
					$("#index.a .link-block:eq("+i+")").stop().animate({height: main_linklock_h-(100-main_linklock_h)/5},250);
				}
			}

			var	obj = $("#index.a .link-block-hovered");
			//obj.stop().animate({height: main_linklock_h},250);
			//$("#index.a .link-block:not(."+$(this).attr("class")+") .back-ground").stop().animate({backgroundColor: '#cfd0d0'},250);
			$("#index.a .link-block big").stop().animate({opacity: 1},250);
			$("#index.a .link-block small").stop().animate({opacity: 0},250,function()
			{
				obj.removeClass("link-block-hovered");
				//promo_focus	= false;
			});

			
			
				this_.addClass("link-block-hovered");
				this_.animate({height: 100},250);
				
				//this_.find(".back-ground").stop().animate({backgroundColor: '#d8201e'},250);	
				
				this_.find("small").stop().animate({opacity: 1},250);
				this_.find("big").stop().animate({opacity: 0},250,function()
				{
					//promo_focus	= false;
				});
		});
	},
	function()
	{		
		$("#city-list").stop();
		var	obj = $(this);
		//promo_focus = true;
		for (i=0;i<6;i++)
		{
			if ($("#index.a .link-block:eq("+i+")").attr("class")!=obj.attr("class"))
			{
				//$("#index.a .link-block:eq("+i+")").stop().animate({height: main_linklock_h},250);
			}
		}
		
		//obj.stop().animate({height: main_linklock_h},250);
		//$("#index.a .link-block .back-ground").stop().animate({backgroundColor: '#cfd0d0'},250);
		$("#index.a .link-block big").stop().animate({opacity: 1},250);
		$("#index.a .link-block small").stop().animate({opacity: 0},250,function()
		{
			obj.removeClass("link-block-hovered");		
			//promo_focus	= false;
		});
	});
	$("#index.a .sub-text").hover(function(){},
	function()
	{		
		$("#city-list").stop();
		//promo_focus	= false;
		var	obj = $("#index.a .link-block-hovered");
				$("#index.a .link-block").stop().animate({height: main_linklock_h},250);
				//obj.find(".back-ground").stop().animate({backgroundColor: '#cfd0d0'},250);
		obj.find("big").stop().animate({opacity: 1},250);
		obj.find("small").stop().animate({opacity: 0},250,function()
		{
			obj.removeClass("link-block-hovered");		
		});
	});

	//  спава продукция
	$("#index.a .splash-r .production .into div.link a").hover(function()
	{
		$(this).find("img").stop();
		$(this).find("img").animate({width: 111, height: 152, marginLeft: -60, top: -25},250);
	},
	function()
	{
		$(this).find("img").stop();
		$(this).find("img").animate({width: 73, height: 100, marginLeft: -40, top: 0},250);
	});
	
	// инпуты формы
	$("#index.a .splash-r .text-input input").focus(function()
	{
		if ($(this).get(0).value==$(this).attr("rel"))
		{
			$(this).parent().find("span").hide();
			$(this).attr("value","");
		}
	});
	$("#index.a .splash-r .text-input input").blur(function()
	{
		if ($(this).get(0).value=='')
		{
			$(this).attr("value",$(this).attr("rel"));
			$(this).parent().find("span").show();
		}
	});
	$("#index.a .splash-r .text-input span").click(function()
	{		
		$(this).parent().find("input").focus();
	});
}

function inner_page()
{
	// баннер справа
	$('#index.c .splash-r .banner-block a').hover(function(){
		$(this).find('i').stop().animate({opacity: 1},250);
		$(this).find('s').stop().animate({opacity: 0},250);
	},
	function()
	{
		$(this).find('s').stop().animate({opacity: 1},250);
		$(this).find('i').stop().animate({opacity: 0},250);
	});

	// выезд элементов	
	$("#index.b .splash-r").hover(function()
	{
		//if ($("#index.b #top").width()>=1400) return false;
			is_expanding_r=false;
			$(".splash-r").addClass("splash-r-hovered");
			
			if ($.browser.msie)
				$(".splash-r").width(210);
			else
				$(".splash-r").stop().animate({width: 210},500);
			//$(".splash-r .text").stop().animate({right: 0},500);
			//collapse_left();
	},
	function()
	{
		//if ($("#index.b #top").width()>=1400) return false;

		$(".splash-r").removeClass("splash-r-hovered");
		if ($.browser.msie)
			$(".splash-r").get(0).style.width='60px';
		else
			$(".splash-r").stop().animate({width: 60},500);	
	});
	$("#index.c .splash-l").hover(function()
	{
		is_expanding_r=false;
		$(".splash-l").addClass("splash-r-hovered");

		if ($.browser.msie)
		{
			if (ie==57)
			{
				$(this).css("background-position","230px");
			}
			$(".splash-l").get(0).style.width='230px';
		}
		else
			$(".splash-l").stop().animate({width: 230},500);			
	},
	function()
	{
		$(".splash-l").removeClass("splash-l-hovered");
		if ($.browser.msie)
		{
			if (ie==57)
			{
				$(this).css("background-position","60px");
			}
			$(".splash-l").get(0).style.width='60px';
		}
		else
			$(".splash-l").stop().animate({width: 60},500);
	});

	// промо блоки
	$("#index .splash-l .promo-elems .elem").hover(function()
	{
		var this_ = $(this);
		
		if ($.browser.msie)
		{
			this_.find("small").show();
			this_.find("big").hide();
			this_.find("sup").hide();
			this_.find("sub").css('filter','alpfa(opacity=100)').show();
		}
		else
		{
			this_.find("small").stop().animate({opacity: 1},250);
			this_.find("big").stop().animate({opacity: 0},250);
			this_.find("sup").stop().animate({opacity: 0},250);
			this_.find("sub").stop().animate({opacity: 1},250);		
		}
	},
	function()
	{
		if ($.browser.msie)
		{
			$(this).find("small").hide();
			$(this).find("big").show();
			$(this).find("sup").show();
			$(this).find("sub").hide();
		}
		else
		{
			$(this).find("small").stop().animate({opacity: 0},250);
			$(this).find("big").stop().animate({opacity: 1},250);
			$(this).find("sup").stop().animate({opacity: 1},250);
			$(this).find("sub").stop().animate({opacity: 0},250);
		}
	});

	// аккордеон
	$("#index.b .splash-l .right dl dt").hover(function()
	{		
		if ($(this).parent().attr("class").indexOf("expanded")>0) return false;
		$(this).parent().addClass("hovered");
		var this_ = $(this);
		this_.parent().find("big").stop().animate({opacity: 0},250);
		this_.stop().animate({color: '#da2625'},250);
	},
	function()
	{
		if ($(this).parent().attr("class").indexOf("expanded")>0) return false;
		$(this).parent().removeClass("hovered");
		var this_ = $(this);
		this_.parent().find("big").stop().animate({opacity: 1},250);
		this_.stop().animate({color: '#ffffff'},250);
	});
	
	var flag = true;
	$("#index.b .splash-l .right dl").click(function()
						{
							var o = $(this).find("dd");
							//o = o.find("dd");
							//$("#left-menu dl").stop();
							var p_obj = $("#index.b .splash-l .right dl.expanded dd");
							p_obj.animate({height: 0},300,function()
							{
								p_obj.parent().removeClass("expanded");								
								p_obj.parent().find("big").stop().animate({opacity: 1},250);
								p_obj.parent().find("dt").stop().animate({color: '#ffffff'},250);
								// скукоживаем обратно высоту области просмотра								
								h_ = document.getElementsByTagName('html')[0].clientHeight;
								$("#index.b .splash-l .left").height(h_-70);
								$("#index.b .splash-r").height(h_);	
								set_all_size();
							});
							
							if ((o.parent().attr("class").indexOf("expanded")==-1) && (flag))
							{
								flag = false;
								var h_ = o.get(0).scrollHeight - o.get(0).clientHeight+26;
								
								// пляски с бубном: дело в том что при первом раскрытии ,если текст настолько
								// длиннен что вызывает скроолл страницы, аккордеон сжимается на величину ширины
								// скролл бара и текст увеличивается, что вызывает эффективное увеличение
								// высоты контента аккордеона и его нижняя граница прижимается к тексту
								
								if (p_obj.length==0) h_ = h_+20;
								//if ($(this).find("dt").html()=='Термины пластикового окна') h_=4609;
								
								o.animate({height: h_},300,function()
								{
									o.parent().addClass("expanded");
									o.parent().removeClass("hovered");
									flag = true;
									set_all_size();

									//h_ = o.find("dd").get(0).scrollHeight - o.find("dd").get(0).clientHeight+26;
									
									//o.height(h_);
									//$("#index.b .splash-l .footer").show();
								});
							}
						});
	$(".accordion-2 dt span").click(function()
	{
							var o = $(".accordion-2").has($(this));
							o = o.find("dd");
						
							var p_obj = $(".accordion-2 dd.expanded");
							p_obj.animate({height: 0},200,function()
							{
								p_obj.removeClass("expanded");
								// скукоживаем обратно высоту области просмотра								
								h_ = document.getElementsByTagName('html')[0].clientHeight;
								$("#index.c .splash-r .right").height(h_);
								$("#index.c .splash-l").height(h_);	
								set_all_size();
							});

							if ((o.attr("class")!="expanded") && (flag))
							{
								flag = false;
								var h_ = o.get(0).scrollHeight - o.get(0).clientHeight;// + o.find("dt").height();
								
								o.animate({height: h_},200,function()
								{									
									o.addClass("expanded");
									flag = true;
									set_all_size();
								});
							}
	});
						
	// инпуты формы
	form_inputs();
	$(".call-form .button").click(function()
	{
		// валидация времени
		if ($(".form-elem-2 .wrapper-right input").length==0) return 0;
		str_ = $(".form-elem-2 .wrapper-right input").get(0).value;
		arr_ = str_.split(":");
		h_ = 1*arr_[0];
		m_ = 1*arr_[1];

		if ((h_!=h_) || (m_!=m_)) {			
			$("#label-of-error").html("неверный формат времени");
			return false;
		}
		if ((h_>23) || (h_<0) || (m_>60) || (m_<0)) {
			$("#label-of-error").html("неверный формат времени");
			return false;
		}
		// валидация даты
		var d = new Date();
		str_ = $(".form-elem-2 .wrapper-left .text").get(0).value;
		arr_ = str_.split(".");	
		d.setFullYear(arr_[2]);
		d.setMonth(arr_[1]);
		d.setDate(arr_[0]);
		
		year_ =d.getFullYear();
		month_ = d.getMonth(); if (month_<10) month_="0"+month_;
		day_ = d.getDate(); if (day_<10) day_="0"+day_;
		
		//lert(day_+'.'+month_+'.'+year_);
		
		if ((day_+'.'+month_+'.'+year_) != str_)
		{
			$("#label-of-error").html("неверный формат даты");
			return false;
		}

		// валидация текстовых полей
		strerr = 'Вы не заполнили поля:';
		for (i=0;i<$(".call-form .form-elem").length;i++)
		{
			obj = $(".call-form .form-elem:eq("+i+")");
			if (obj.find("input").length>0)			
			{
				subobj =  obj.find("input");

				if ((subobj.get(0).value=='') || (subobj.get(0).value==subobj.attr("rel")))
					strerr = strerr+' '+subobj.attr("rel")+',';
			}
		}
		
		if (strerr!= 'Вы не заполнили поля:')
		{
			strerr = strerr.substr(0,strerr.length-1);
			$("#label-of-error").html(strerr);	
			return false;
		}
		else
			$("#label-of-error").html("");
	});
	
	// левое меню
	$("#index.b ul.menu li span,#index.c ul.menu li span").hover(function()
	{
		if ($(this).parent().attr("class").indexOf('active')<0)
		{
			$(this).css("color","#ff0000");
			$(this).stop().animate({fontSize: 24,marginTop: -15},150);
		}
	},
	function()
	{
		if ($(this).parent().attr("class").indexOf('active')<0)
		{
			
			if ($(this).parent().parent().attr("class")=='sub-menu')
				$(this).stop().animate({fontSize: 14,marginTop: -11},150,function()
				{
					$(this).attr("style","");
				});
			else
				$(this).stop().animate({fontSize: 16,marginTop: -10},150,function()
				{
					$(this).attr("style","");
				});
		}
	});
	
	// время "вызов замерщика"	
	$("#index.b .wrapper-right input").keypress(function(e)
	{
		//alert(e.keyCode);
		len_ = $(this).get(0).value;
		if ((e.which==58) || (e.which==32))
		{
			if ((len_.length==2) || (len_.length==5))
			{
				$(this).attr("value",$(this).get(0).value + ":");
				return false;
			}
		}
		
		var cond = ((e.which >= 48) && (e.which  <= 57)) || (e.which<9) || (e.which==32) 
		|| (e.which==40) || (e.which==41) || (e.which == 0) || ((e.keyCode>=37) && (e.keyCode<=40)) || (e.keyCode==46);
		
		 if ($.browser.opera)
												   {
													   cond = cond || ((e.which<9) || (e.which==46) || (e.which==37) || (e.which==39)
																	|| (e.which==35) || (e.which==36)
																)
												   }

		
		if (!cond) return false;		
		
		code_ = e.which;
		if ((len_.length==2) && (e.keyCode!=8))
		{
			$(this).attr("value",$(this).get(0).value + ":");
			//return false;
		}
		if (len_.length==0)
		{
			/*if (code_!=49)
			{
				$(this).attr("value",$(this).get(0).value + "0");
				return false;
			}
			*/
		}
		if ((len_.length==3) && (e.keyCode!=8))
		{
			//if ((code_!=48) && (code_!=51)) return false;
		}
		if ((len_.length==4) && (e.keyCode!=8))
		{
			/*if (code_!=48) 
			{
				$(this).attr("value",$(this).get(0).value + "0");
				return false;
			}
			*/
		}
		if ((len_.length==5)&& (e.keyCode!=8))
		{
			if (!(((e.keyCode>=37) && (e.keyCode<=40)) || (e.keyCode==46)))
				return false;
		}
	});
	// дата "вызов замерщика"	
	$("#index.b .wrapper-left input").keypress(function(e)
	{
		len_ = $(this).get(0).value;
		if ((e.which==46) || (e.which==32))
		{
			if ((len_.length==2) || (len_.length==5))
			{
				$(this).attr("value",$(this).get(0).value + ".");
				return false;
			}
		}
	
		var cond = ((e.which >= 48) && (e.which  <= 57)) || (e.which<9) || (e.which==32) 
		|| (e.which==40) || (e.which==41) || (e.which == 0) || ((e.keyCode>=37) && (e.keyCode<=40)) || (e.keyCode==46);
		
		 if ($.browser.opera)
												   {
													   cond = cond || ((e.which<9) || (e.which==46) || (e.which==37) || (e.which==39)
																	|| (e.which==35) || (e.which==36)
																)
												   }

		
		if (!cond) return false;
		
		
		
		code_ = e.which;
	
		if ((len_.length==2) && (e.keyCode!=8))
		{
			$(this).attr("value",$(this).get(0).value + ".");
			//return false;
		}
		
		if ((len_.length==5) && (e.keyCode!=8))
		{
			$(this).attr("value",$(this).get(0).value + ".");
		}
		
		if ((len_.length==10)&& (e.keyCode!=8))
		{
			 if (!(((e.keyCode>=37) && (e.keyCode<=40)) || (e.keyCode==46)))
				return false;
		}
	});

	$("#index.b input[name='form_text_31']").keypress(function(e)
	{
		var cond = ((e.which >= 48) && (e.which  <= 57)) || (e.which<9) || (e.which==32) 
		|| (e.which==40) || (e.which==41);
		
		 if ($.browser.opera)
												   {
													   cond = cond || ((e.which<9) || (e.which==46) || (e.which==37) || (e.which==39)
																	|| (e.which==35) || (e.which==36)
																)
												   }

		
		if (!cond) return false;
		//"input:first").attr("value",e.which);
	});
	
	$("#index.b .wrapper-left input").datePicker({
		createButton:true,
		clickInput:false,
		startDate: '01-01-2000'
	});
	$("#index.b .wrapper-left a").click(function()
	{
		$("#index.b .wrapper-left img").click();
		return false;
	});
	
	$("#index.b .splash-l .wrapper-left input:last").change(function()
	{
	//alert("!");
		if ($(this).get(0).value!='Дата')
			$("#index.b .splash-l .wrapper-left input").addClass("text-hovered");
	});	
	
	// форма вакансии
	//form_inputs
	$("#vacansy-ancet").click(function()
	{	
		$("#sert-wrapper").addClass("loaded");
		$("#sert-wrapper").animate({opacity: 1},250);
		$("#sert-wrapper").css("left","0");
		$("#sert-wrapper .blend").css("display","block");
			
		$.get('/partners/vacancy_form.php',{ajax: 'Y'},function(data)
		{
			$("#sert-wrapper .picture").html(data);			
			$("#sert-wrapper .picture").css("width","80%");
			h_ = -$("#sert-wrapper .picture").height()/2;
			w_ = -$("#sert-wrapper .picture").width()/2;
			$("#sert-wrapper .picture").css("margin",h_+'px 0 0 '+w_+'px');

			$("#sert-wrapper .picture").css("left","50%");
			$("#sert-wrapper").removeClass("loaded");
			$("#sert-wrapper").css("cursor","default");
			form_inputs();
			
		});
		return false;
	});
}
function mousePageXY(e)
{
	      var x = 0, y = 0;
	     
	      if (!e) e = window.event;
	     
	      if (e.pageX || e.pageY)
	      {
	        x = e.pageX;
	        y = e.pageY;
	      }
	      else if (e.clientX || e.clientY)
	      {
	        x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
			y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
	      }
     
	      return x;
}

function collapse_left()
{
		is_expanding_l = false;
		if ($.browser.msie)
		{
			$(".splash-l").width(60);
			$(".splash-l").removeClass("splash-l-hovered");
			$("#index.b .splash").height(document.getElementsByTagName('html')[0].clientHeight);
			is_expanding_l = true;
		}
		else
		{
			$(".splash-l").stop().animate({width: 60},500,function()
			//$(".splash-l .text").stop().animate({left: -w_/2},500,function()
			{
				$(".splash-l").removeClass("splash-l-hovered");
				$("#index.b .splash").height(document.getElementsByTagName('html')[0].clientHeight);
				is_expanding_l = true;
			});
		}
}

function collapse_right()
{
	is_expanding_r = false;
				if (is_oldopera)
					$(".splash-r .text").hide();
	if ($.browser.msie)
	{
		$(".splash-r").width(60);
		$(".splash-r").removeClass("splash-r-hovered");
		is_expanding_r = true;
	}
	else
	{
		$(".splash-r").stop().animate({width: 60},500,function()
		//$(".splash-r .text").stop().animate({right: -w_/2},500,function()
		{
			$(".splash-r").removeClass("splash-r-hovered");
			is_expanding_r = true;
		});
	}
}

// установление высоты левой выезжающей части на внутренних страницах
function set_height_left()
{
	var h_ = $(".splash-l .right").innerHeight();
	var h2_ = $(".splash-l .left").innerHeight();
	if (h2_>h_) h_ = h2_;
	if (h_>document.getElementsByTagName('html')[0].clientHeight)
	{	
		$(".splash").height(h_);
	}
	
}

// Установить куки
function setCookie(name, value) {
      var valueEscaped = escape(value);
      var expiresDate = new Date();
      expiresDate.setTime(expiresDate.getTime() + 365 * 24 * 60 * 60 * 1000); // срок - 1 год, но его можно изменить
      var expires = expiresDate.toGMTString();
      var newCookie = name + "=" + valueEscaped + "; path=/; expires=" + expires;
      if (valueEscaped.length <= 4000) document.cookie = newCookie + ";";
}

// Получить куки
function getCookie(name) 
{
      var prefix = name + "=";
      var cookieStartIndex = document.cookie.indexOf(prefix);
      if (cookieStartIndex == -1) return null;
      var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length);
      if (cookieEndIndex == -1) cookieEndIndex = document.cookie.length;
      return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex));
}

function mousePageXY_(e)
{
	      var x = 0, y = 0;
		  var arr_ = [];
	     
	      if (!e) e = window.event;
	     
	      if (e.pageX || e.pageY)
	      {
	        x = e.pageX;
	        y = e.pageY;
	      }
	      else if (e.clientX || e.clientY)
	      {
	        x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
			y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
	      }
     
		arr_[0]=x;
		arr_[1]=y;
	      return arr_;
}

function form_inputs()
{
	//.change
	// событие сабмита
	if ($(".form-elem-2 .wrapper-right input").length==0)
	{
		$(".form-elem  input.button-left").die();
			$(".form-elem  input.button-left").live("click",function()
			{
				for (i=0;i<4;i++)
				{
					obj = $(".form-elem:eq("+i+") input");
					if (obj.get(0).value==obj.attr("rel"))
					{
						$("#label-of-error").html("Не заполнено поле: "+obj.attr("rel"));
						$("#label-of-error").show();
						return false;
					}
				}
				obj  = $(".form-elem textarea");
				if (obj.html()==obj.attr("rel"))
				{
					$("#label-of-error").html("Не заполнено поле: "+obj.attr("rel"));
					$("#label-of-error").show();
					return false;
				}
				//web_form_submit
				$("form[name='VACANCY']").ajaxSubmit(function(data)
				{
					popup_unload();
				});
			});
	}
	
	$("#index .form-elem input.text").focus(function()
	{
		if (($(this).attr("rel")!='#date#') && ($(this).attr("rel")!='#time#'))
		{
			if ($(this).get(0).value==$(this).attr("rel"))
			{
				$(this).attr("value","");
				$(this).addClass("text-hovered");
			}
		}
		else
		{
			if ($(this).get(0).value=='Дата')
			{
				$(this).attr("value",$(this).parent().find('.a').get(0).value);
				$(this).addClass("text-hovered");
			}
			if ($(this).get(0).value=='Время')
			{
				// текущее время
				current_date =  new Date();
				minut = current_date.getMinutes();
				if (minut<10) minut = '0'+minut;
				
				hour = current_date.getHours();
				if (hour<10) minut = '0'+hour;
				
				$(this).attr("value",hour+":"+minut);
				$(this).addClass("text-hovered");
			}
		}
	});
	$("#index .form-elem input.text").blur(function()
	{
		if (($(this).attr("rel")!='#date#') && ($(this).attr("rel")!='#time#'))
		{
			if ($(this).get(0).value=='')
			{
				$(this).attr("value",$(this).attr("rel"));
				$(this).removeClass("text-hovered");
			}
		}
		else
		{
			if (($(this).get(0).value=='') && ($(this).attr("rel")=='#date#'))
			{
				$(this).attr("value",'Дата');
				$(this).removeClass("text-hovered");
			}
			if (($(this).get(0).value=='') && ($(this).attr("rel")=='#time#'))
			{
				$(this).attr("value",'Время');
				$(this).removeClass("text-hovered");
			}
		}
	});
	$("#index .form-elem textarea").focus(function()
	{
		if ($(this).get(0).value==$(this).attr("rel"))
		{
			$(this).html("");
			$(this).addClass("textarea-hovered");
		}
	});
	$("#index .form-elem textarea").blur(function()
	{
		if ($(this).get(0).value=='')
		{
			$(this).html($(this).attr("rel"));
			$(this).removeClass("textarea-hovered");
		}
	});
}

function popup_unload()
	{
		if ($.browser.msie)
			$("#sert-wrapper").show();
		else
			$("#sert-wrapper").animate({opacity: '0'},250);

			$("#sert-wrapper .blend").css("display","none");
			$("#sert-wrapper .picture").css("left","-200%");
			$("#sert-wrapper").css("left","-200%");
			
			$("#sert-wrapper .spinner").attr("style","");
			$("#sert-wrapper").css("cursor","pointer");

			is_not_expanding = false;
	}
	
function open_video()
	{
		is_not_expanding = true;

		flash_ = '<div style="border:1px solid #cdcdcd;"><object width="720" height="580"><param name="movie" value="/videoPlayer.swf"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><param name="flashvars" value="url=/videos/romax2.flv&play=true"></param><embed flashvars="url=/videos/romax2.flv&play=true" src="/videoPlayer.swf" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="720" height="580"></embed></object></div>'
		$("#sert-wrapper .picture").html(flash_);
		var w_ = 720;
		var h_ = 580;
		$("#sert-wrapper").animate({opacity: 1},250);
		$("#sert-wrapper .picture").css("margin",-h_/2+"px 0 0 -"+w_/2+"px");
		$("#sert-wrapper").css("left","0");
		$("#sert-wrapper .blend").css("display","block");
		$("#sert-wrapper .picture").css("left","50%");
		$("#sert-wrapper .picture").css("cursor","default");			
	}
	
function WbrSleep(time_ms,function_)
{
	return setTimeout(function_, time_ms);
}

