$(document).ready(function() {


			$("a.zoom").fancybox();

			$("a.zoom1").fancybox({
				'overlayOpacity'	:	0.7,
				'overlayColor'		:	'#FFF'
			});

			$("a.zoom2").fancybox({
				'zoomSpeedIn'		:	500,
				'zoomSpeedOut'		:	500,
				'overlayShow'		:	false
			});
			
		

	/* вылезающее подменю у главного меню*/
	$("#menues").hover( function(){
		
		$("#mainMenuTxt a").hover(function(){
			var podMenuNum = $(this).attr("rel");
			
			$(".podMenu_"+podMenuNum+"").animate({opasity: "show", bottom: "-50px"},"slow")
			.siblings("#podMenu:visible").animate({opasity: "hide", bottom: "-10px"},"fast");
			return false;
		}, function(){
			$(".podMenu_"+podMenuNum+"").animate({opasity: "hide", bottom: "-10px"},"fast");
	});
	},function(){
		$(this).children("#podMenu:visible").animate({opasity: "hide", bottom: "-10px"},"fast");
	});
	
	//подгоняем левый край по гл меню
	$("#phonesAndLogin").css("left", $("#headerRight").width() - $("#menues").width()+"px");

	/*  логинимся, действие на кнопке */
	$("#logIn").hover(function(){
		$(".logInTxtBut").click( function(){
			$("#logInForm").animate({opasity: "show"}, "fast");
			return false;
		});
	}, function(){
			$("#logInForm").animate({opasity: "hide"}, "fast");	
			return false;	
		});
	$(".logInBut").click( function(){//вход
		$(".authForm").submit();
		return false;
	});
	$(".logOutBut").click( function(){//выход
		$(".authForm").submit();
		return false;
	});
	/* корзина*/
	//alert($(".winTblBox").width());
	
	var center = Math.round($(".winTblBox").width()/2);
	var delta = 35;
	if($.browser.opera)
		delta = 50;
	$("#shopCart").css("left",center-delta+"px");
	$("#shopCart").click(function(){
		document.location.href = "/basket/";
	});

	
	//$("#pageContentCenter").css("margin","0px 0px 0px 290px");
	if($.browser.msie)
	{
		//$('#podMenu').css('margin-left','20px');
		//$("#pageContentCenter").width(100+'px');
		$("#pageContentCenter").css("margin","0px 0px 0px 0px");
		$("#pageContentCenter.indexPage").css("margin","0px 0px 0px 0px");
		$("#pageContentCenter table").width(98+"%");
		motherTbl = $("#pageContentCenter").width();
		$(".simpleTblCenterTD").width( motherTbl - 50 + 'px')
		var mW = $("#menues").width();
		$("#menues").width( mW+1+'px');
		//$("#pageContentCenter").css("padding","0px 10px 0px 290px");
		//$("#pageContentCenter").css("border","1px solid #000");
		//$("#pageContentCenter").css("float","right");
		//$("#pageContentCenter").css("top","0px");
		
		/*   предупреждение о старом браузере  */
		var txt = '<div id="badBrowser">Вы используете устаревший браузер.<br>Для корректного отображения сайта установите последнюю версию любого из браузеров: <a href="http://www.mozilla-russia.org/">Mozilla Firefox</a>, <a href="http://ru.opera.com/download/">Opera</a>, <a href="http://www.google.com/chrome?hl=ru">Google Chrome</a>, <a href="http://www.microsoft.com/rus/windows/internet-explorer/" style="text-decoration:line-through;">Internet Explorer</a></div>';
		
		var k = 0;
		jQuery.each($.browser, function(i, val) {
			//alert($.browser.version.substr(0,1));
			
			if( $.browser.version.substr(0,1)< 7 && k==0 )
      		{
				$(txt).appendTo("#warning");
				$("#warning").show();
			}
			k++;
 		});

	};
	
/* подменю каталога */
	/*формируем меню*/
	//dropMenuY = parseInt($("#dropMenu").css("top").substring(0,$("#dropMenu").css("top").indexOf("px")));
	//alert(dropMenuY)
	$("#catalogMenu").hover( function(){

	$("#catalogMenu ul li").hover( function(){//вылезает меню
	

		//заполняем меню
		var menuTxt = "";
		if( $.browser.msie )
			menuTxt = $(this).find("div:first").html();
		else
			menuTxt = $(this).next("div:first").html();
		//alert ($(this).find("div:first").width());
		if( menuTxt != null)
		{
		
		$(".dmMenuTxt").empty().append(menuTxt);
		
				
		
		//title=dmSTRpos.top+'-'+dmCCH+'-'+delta;

		//меняем название для гл раздела вверху менюшки
		title = $(this).attr("rel");
		$(".razName").empty().append(title);
		// показываем
			$("#dropMenuBox").stop(true,true).animate({opasity:"show"}, "slow");
			//alert ( $(".dmMenuTxt").width() );//высота и ширина
			var dmCCW	= $(".dmMenuTxt").width() + 20;
			var dmCCH	= $(".dmMenuTxt").height() + 20;
			$("#dropMenu").width( dmCCW+"px" );
			$("#dropMenu").height( dmCCH +"px" );
			$("#dmCU").width( dmCCW + "px" );
			$("#dmCD").width( dmCCW + "px" );
			$("#dmLC").height( dmCCH +"px" );
			$("#dmRC").height( dmCCH +"px" );
			// позиционируем по верхнему или нижнему краю ГЛ. меню
			var dmMenuTop = $("#catalogMenu ul li:first").position();
			var dmSTRpos = $(this).position();
			//title= dmSTRpos.top;
			$("#dmSTR").css("top",dmSTRpos.top-4+"px");

			var delta = dmSTRpos.top-dmCCH+18;
			if( dmSTRpos.top > (dmCCH+19) )
				dmMenuPos = dmMenuTop.top+delta;
			else
				dmMenuPos = dmMenuTop.top;
			$("#dropMenu").css("top",dmMenuPos-10+"px");
			
		}
		else
			$("#dropMenuBox").stop(true,true).animate({opasity:'hide'},'fast');
		});
	}, function(){//убираем меню
		$("#dropMenuBox").stop(true,true).animate({opasity:'hide'},'fast');
	});

	/**/
	if($.browser.msie)
	{
		//alert($("#pageContentCenter").width());
		$(".TBL_100").width( $("#pageContentCenter").width()-10+"px");
		$(".TBL_100 #contHeaderRight").width($(".TBL_100").width()-100+"px");
		$(".TBL_100 #contHeaderRight").css("margin-top","10px")
		maxSelWDelta = 36;
	}
	else
	{	
		$(".TBL_100").width("100%");
		maxSelWDelta = 36;
	}
	
	
	/*подгоняем поля "селект"*/
	
	// 1ое поле
	$(".selTxt").find("p.selected").css("display","block");
	var maxSelW = 0;
	$(".selBox p").each( function(){
		if( $(this).width() > maxSelW )
			maxSelW = $(this).width();
	});
	//maxSelWDelta = 36;//разница для разных браузеров
	$("#showPrice").width( maxSelW +maxSelWDelta+"px");
	$(".selBox").children("p").width(maxSelW +14+"px");
	$("#selBoxCD").width(maxSelW +maxSelWDelta+"px");
	if($.browser.msie)
	{
		$("#selBoxLD").css({"bottom":"-19px"});
		$("#selBoxRD").css({"bottom":"-19px","right":"0px"});
		//$("#selBoxCD").css({"bottom":"-30px", "height":"8px"});
	}
	//2ое поле
	$(".selBrandsTxt").find("p.selected").css("display","block");
	var maxSelBW = 0;
	$(".selBrandsBox p").each( function(){
		if( $(this).width() > maxSelBW )
			maxSelBW = $(this).width();
			//alert(maxSelBW);
	});
	//maxSelWDelta = 36;//разница для разных браузеров
	$("#showBrands").width( maxSelBW +maxSelWDelta+"px");
	$(".selBrandsBox").children("p").width( maxSelBW +14+"px");
	$("#selBrandsBoxCD").width(maxSelBW +maxSelWDelta+"px");
	if($.browser.msie)
	{
		$("#selBrandsBoxLD").css({"bottom":"-14px"});
		$("#selBrandsBoxRD").css({"bottom":"-14px","right":"0px"});
	}
	$("#showBrandsTxt").height( $("#selBrandsBox").height() + "px")

	$(".divSelect").hover( function(){
	
	$(".selBox p.selected, #showPrice .showSelArrow").click( function(){
		$(".selBox").children("p:not(.selected)").css("background","#414244");
		$(".selBox").children("p:not(.selected)").width(maxSelW +14+"px");
		
		$(".selBox p").stop(true,true).each( function(){
			if ( $(this).hasClass("active").toString() == "false" )
			{
			$(this).stop(true,true).slideDown("slow", function(){
				$(".selBoxFooter").stop(true,true).slideDown("slow").addClass("active");
			}).addClass("active");
			}
		});
	});
		/*  выбор селекта для вывода, цена/название */
		$(".selBox p a").click( function(){
			var orderBy = $(this).attr("orderby");
			//$("#selPriceForm input:first").attr("value",orderBy);
			$("#selectForm input[name=selPriceOption]").attr("value",orderBy);
			
			//if( $("#selPriceForm input:first").attr("value") != "0" )
			if( $("#selectForm input[name=selPriceOption]").attr("value") != "" )
				//$("#selPriceForm").submit();
				$("#selectForm").submit();
			//alert(orderBy);
		return false;
		});
		/**/
	
	}, function(){
		$(".selBox p").stop(true,true).each( function(){
			$(".selBox p:visible:not(.selected)").stop(true,true).slideToggle("slow", function(){
				$(".selBoxFooter").stop(true,true).slideUp("fast").removeClass("active");
			}).removeClass("active");
		});
	});
	
	/*  22222 */
	/*
	$(".divBrandsSelect").hover( function(){
	
	$(".selBrandsBox p.selected, #showBrands .showSelArrow").click( function()
	{
		$(".selBrandsBox").children("p:not(.selected)").css("background","#414244");
		$(".selBrandsBox").children("p:not(.selected)").width(maxSelBW +14+"px");
		
		$(".selBrandsBox p").stop(true,true).each( function(){
			if ( $(this).hasClass("active").toString() == "false" )
			{
				$(this).stop(true,true).slideDown("slow", function(){
					$(".selBrandsBoxFooter").stop(true,true).slideDown("slow").addClass("active");
				}).addClass("active");
			}
		});
		*/
		/*  выбор селекта для вывода, производитель  */
		/*$(".selBrandsBox p a").click( function(){
			var orderBy = $(this).attr("id");
			//$("#selBrandForm input:first").attr("value",orderBy);
			$("#selectForm input[name=selBrandOption]").attr("value",orderBy);
			
			//if( $("#selBrandForm input:first").attr("value") != "0" )
			if( $("#selectForm input[name=selBrandOption]").attr("value") != "" )
				//$("#selBrandForm").submit();
				$("#selectForm").submit();
			//alert(orderBy);
		return false;
		});
	});
	}, function(){
		$(".selBrandsBox p").stop(true,true).each( function(){
			$(".selBrandsBox p:visible:not(.selected)").stop(true,true).slideToggle("slow", function(){
				$(".selBrandsBoxFooter").stop(true,true).slideUp("fast").removeClass("active");
			}).removeClass("active");
			//$(".selBrandsBox").css("display","none");
		});
		$(".selBrandsBox p:visible:not(.selected").css("display","none");
	});
	*/
	/* валюта по умолчанию */
	$("#money a").click( function(){
		var id = $(this).attr("id");
		//alert (id);
		$("#showCurrency input:first").attr("value", id);
		if( $("#showCurrency input:first").attr("value") != "" )
		$("#showCurrency").submit();	
		return false;	
	});
	
	/*клик на картинке у товара РАСПРОДАЖА*/
	$(".saleTmpIMG").click( function(){
		var iW = $(this).next(".goodIMG a img:first").width();
		var iH = $(this).next(".goodIMG a img:first").height();
		$(this).width(iW+'px');
		$(this).height(iH+'px');
		
	});
	//действия в корзине, при оформлении товара
	$(".typeOfUser").click( function(){
		if( $(this).attr("value") == "ur" )
		{
			//открываем поле для юр информации
			$("tr.rekvisity").animate({opasity: "show"},"fast");
			// меняем способ оплаты на безнал,остальныеделаем неактивными
			$("div.oplata input").each( function(){
				if( $(this).attr("value") == "oplataBeznal" )
					$(this).attr("checked","checked");
				else
					$(this).attr("disabled","disabled");
			});
		}
		else if( $(this).attr("value") == "fiz")
		{
			//закрываем поле для юр информации
			$("tr.rekvisity").animate({opasity: "hide"},"fast");
			// меняем способ оплаты на безнал,остальныеделаем неактивными
			$("div.oplata input").each( function(){
					if( $(this).attr("value") == "oplataNal" )
						$(this).attr("checked","checked");
					$(this).removeAttr("disabled");
			});
		}
	});
	//$(".goodIMG").next("img:first").attr("border","10");
	if($.browser.opera)
	{
		$(".goodCard").find("a").css("color","#414244");
		$("div.catRazdely").find("a").css({	"color":"#414244",
											"font-weight":"normal",
											"font-family":"Tahoma",
											"text-decoration":"underline"
										});
		$(".contHeaderMenu").find("a").css({"color":"#7171eb","font-size":"14px"});
		
		$("div.copyright p").css({"color":"#000",
								"font-weight":"normal",
								"font-family":"Tahoma",
								"text-decoration":"none",
								"display":"block"
								});
		$(".footerMenu a").css({	"color":"#000",
									"font-weight":"normal",
									"font-family":"Tahoma",
									"text-decoration":"none"
								});
	}
	
	var addW = 20;
	var sWidth = $("#sel").width();
	$("#selBox").width(sWidth+addW+'px');
	$("#selBoxLeft").width(sWidth+addW+'px');
	
	var sWidth2 = $("#sel2").width();
	$("#selBox2").width(sWidth2+addW+'px');
	$("#selBoxLeft2").width(sWidth2+addW+'px');
	
	$(".sel").change( function(){
		formName = $(this).attr("name");
		formName += 'Form';
		//alert(formName);
		$("#"+formName).submit();
	});
	
	/*
	 * При фиксированной ширине сайта в 1020 точек
	 * каждый 2ой товар на витрине
	 * имеет отступы
	 */
	var $goodBoxNum = 2;
	if( $("div.generalBox").width() == 1020 )
	{
		$("div.goodBox").each(function(){
			if( $(this).attr("id") == $goodBoxNum )
			{
				$(this).css({"margin-left":"20px","margin-right":"20px"});
				$goodBoxNum +=3;
			}
		});
	}
	
	/*
	*	Приводит все таблицы на странице к одному виду/стилю 
	*/
	$(".mainTxt  table:not(:first)").each( function(){
		$(this).removeAttr("style");
		$(this).css({
			"width":"100%",
			"border-collapse":"collapse"
		});
		$(this).attr("border","0");
		
		
		//}
		$(this).find("td").removeAttr("style");
		//все
		$(this).find("td").css({
		"padding":"3px 5px 3px 10px",
		"font-family":"Tahoma",
		"color":"#666666",
		"font-size":"0.85em"
		});
		//нечетные
		$(this).find("tr:not(:even) > td:not(:last)").css("border-right","1px solid #f0f0f0");
		$(this).find("tr:not(:even) > td:not(:last)").css("border-bottom","1px solid #f0f0f0");
		$(this).find("tr:not(:even) > td:not(:last)").css("background","#f9f9f9");
		//четные
		$(this).find("tr:even").css("background","#f0f0f0");
		
	});
	
	$("#uis_consultant_wind").css("z-index","1000");
	$("#uis_consultant_wind_h").css("z-index","1000");
	
});
