function setheight()
	{
    	h=$(window).height()-$("#td1").height()-$("#td3").height();
		$("#td2").css("height", h);
		$("#tb2").css("height", h);
	}

$(document).ready(function()
	{
		setheight();
	}
);


// Если изменяются размеры окна
$(document).ready(function() {
$(window).resize(function ()
	{
    	setheight();
    });
});


$(document).ready(function() {

$(".but").each(function(i)
	{
		$(this).html("<span><span><span>"+$(this).html()+"</span></span></span>");
	});

$(".but").hover(function(){
	$(this).children().addClass("hover");
});

$(".but").mouseout(function(){
	$(this).children().removeClass("hover");
	$(this).children().removeClass("down");
});

$(".but").mousedown(function(){
	$(this).children().removeClass("hover");
	$(this).children().addClass("down");
});

$(".but").mouseup(function(){
	$(this).children().removeClass("down");
	$(this).children().addClass("hover");
});

});

/* запрет выделения текста - плагин jQuery */
//$(function() {$('.but').disableTextSelect();});
//(function($){if($.browser.mozilla){$.fn.disableTextSelect=function(){return this.each(function(){$(this).css({'MozUserSelect':'none'});});};$.fn.enableTextSelect=function(){return this.each(function(){$(this).css({'MozUserSelect':''});});};} else if ($.browser.msie){$.fn.disableTextSelect=function(){return this.each(function(){$(this).bind('selectstart.disableTextSelect', function(){return false;});});};$.fn.enableTextSelect=function() {return this.each(function(){$(this).unbind('selectstart.disableTextSelect');});};} else {$.fn.disableTextSelect=function() {return this.each(function() {$(this).bind('mousedown.disableTextSelect', function() {return false;});});};$.fn.enableTextSelect=function(){return this.each(function(){$(this).unbind('mousedown.disableTextSelect');});};}})(jQuery);




/* Выпадающее меню */
$(document).ready(function() {

$("#menu1 ul").find("a:last").addClass("last");

$("#menu1 li").hover(
	function()
		{
			if ($(this).find("ul").length!=0)
				{
        			$(this).find("ul").css("display", "block");
				}
		},
    function()
		{
            if ($(this).find("ul").length!=0)
				{
        			$(this).find("ul").css("display", "none");
				}
		}
);

});

/* Раскрыть всё */

$(document).ready(function() {

$("#show_all").click(
	function()
		{
			if ($("#category").css("height")=="auto")
				{
        			$("#category").css("height", "112px");
					$(this).find("a").html("Посмотреть весь список");
				}
			else
				{
                    $("#category").css("height", "auto");
					$(this).find("a").html("Свернуть");
				}
		}
);

});

/* Установка высоты у списка */

$(document).ready(function() {

//$("#cat_list li").height(500);

h=0;

$(".set_h li").each(function(i) {
	//h+="_"+$(this).height();
	if ($(this).height()>h) {h=$(this).height();}
});

$(".set_h li").height(h+5);

//alert($(".set_h img").height());


});

/* Карточка товара */
$(document).ready(function() {

$(".a2").hover(
	function()
		{
			$(this).next().css("display", "block");

			w=$(this).width();
            h=$(this).next().height()+30;

			$(this).next().css("margin-left", w+"px");
			$(this).next().css("margin-top", -h+"px");
		},
    function()
		{
            $(this).next().css("display", "none");
		}
);

function check_simb (str)
	{
		str=str.replace(/0/g,"");
		str=str.replace(/1/g,"");
		str=str.replace(/2/g,"");
		str=str.replace(/3/g,"");
		str=str.replace(/4/g,"");
		str=str.replace(/5/g,"");
		str=str.replace(/6/g,"");
		str=str.replace(/7/g,"");
		str=str.replace(/8/g,"");
		str=str.replace(/9/g,"");
		str=str.replace(/\./g,"");
		str=str.replace(/,/g,"");
		if (str!="") {alert("Недопустимые символы"); return false;}	else {return true;}
	}

function number_format(str, count, razd, probel) // строка, кол-во отделяемых знаков, разделитель десятичных знаков, разделитель между группами
	{
		str=String(str);
		str_len=str.length;
		ostatok="00";

		//alert(str);

		point_pos=str.search(/\./);

		if (point_pos!="-1") { /*alert("да");*/ str1=str.substring(0,point_pos); ostatok=str.substr((point_pos+1), 2); str=str1; if (ostatok.length<2) {ostatok+="0";};};

		//alert(str);

		//alert(ostatok);


		new_str="";	for (i=0; i <= str_len; i++) {new_str+=str.substr((str_len-i), 1);}; str=new_str;


		new_str="";
		for (i=0; i < str_len; i=i+3)
			{
				//alert(str.substr(i, 3));
				new_str+=str.substr(i, 3);
				//alert((i+3)+"-"+str_len)
				if (i+3<str_len) {new_str+="";};
			}

        str=new_str; new_str=""; for (i=0; i <= str_len; i++) {new_str+=str.substr((str_len-i), 1);}; str=new_str;
		//alert(new_str);

		new_str+="."+ostatok;

		//alert(new_str);

		return new_str;






	}

function change(this_)
	{
			var error="N";
			if (check_simb($(this_).attr("value")) && $(this_).attr("value"))
				{
		            min_kvanta=eval($(this_).next().next().next().attr("value"));
					v_upak=eval($(this_).next().next().attr("value"));
					shtuk=eval($(this_).attr("value"));
		            cena=eval($(this_).parent().prev().html());
		            summa=shtuk*cena;
					summa=number_format(summa, 3, ".", "");

                    // Штук - shtuk, минимальная кванта - min_kvanta, пользователь ввёл 7 штук, мин. кванта 6 штук, должно выдать сообщение:
					// количество штук должно быть кратным минимальной кванте
					kvanta=shtuk/min_kvanta;

					if (Math.round(kvanta)!=kvanta) {alert("Количество штук должно быть кратным минимальной кванте: "+min_kvanta); error="Y";};


					if (shtuk<min_kvanta) {alert("Минимальное количество "+min_kvanta+" шт."); error="Y";}
					else
						{
							//alert("test3");
		                    up=Math.round(100*(shtuk/v_upak))/100;
							//alert(up);
							$(this_).next().attr("value", up);

							$(this_).parent().parent().find("td:last").find("b").html(summa);
						}
					//alert("test4");

		            var itogo=0;
		            $(".summa").each(function(i)
					{
						//alert(itogo);

						itogo+=eval($(this).html());


					});
					//alert("test5");

					$("#itogo").html(itogo);
				}
			else
				{
					error="Y";
				}
			//alert(error);
			if (error=="Y")
				{
					//alert("reset");
					//$(this_).reset();
					$(this_).parent().parent().find("td:last").find("b").html("");
					//alert(Math.round(kvanta));
					//alert(min_kvanta);
					$(this_).attr("value", Math.round(kvanta)*min_kvanta);
					//alert("test2");
					//$(this_).next().attr("value", min_kvanta);

					change(this_);
				}
};

function change2(this_)
	{
            error="N";
            if (check_simb($(this_).attr("value")) && $(this_).attr("value"))
				{
		            min_kvanta=eval($(this_).next().next().attr("value"));
					v_upak=eval($(this_).next().attr("value"));
					upakovok=eval($(this_).attr("value"));
		            shtuk=upakovok*v_upak;
		            cena=eval($(this_).parent().prev().html());
		            summa=shtuk*cena;
					summa=number_format(summa, 3, ".", "");

					if (shtuk<=0) {alert("Минимальное количество "+min_kvanta+" шт."); error="Y";}
					else
						{
							$(this_).prev().attr("value", shtuk);
							$(this_).parent().parent().find("td:last").find("b").html(summa);
						}

		            itogo=0;
		            $(".summa").each(function(i)
					{
						itogo+=eval($(this).html());
					});
					$("#itogo").html(itogo);
                }
			else
				{
					error="Y";
				}
			if (error=="Y") {$(this_).parent().parent().find("td:last").find("b").html(""); $(this_).prev().attr("value", ""); $(this_).attr("value", "");}
};

$(".sh").change(
	function()
		{
			change($(this));
		}
);

$(".up").change(
	function()
		{
			change2($(this));

            $(".delete").css("opacity", 0.5);
					$(".del").attr("checked", "");
					$(".rewrite").css("opacity", 1);
					$(".rewrite").addClass("submit");
					$(".submit").click(
						function()
							{
								$(this).parents("form").submit();
							}
					);

					$(".rewrite").removeClass("disabled");
		}
);

$(".sh").keypress(function(event){
if (event.keyCode==13) {change($(this));};
});

$(".up").keypress(function(event){
if (event.keyCode==13) {change2($(this));};
});


$(".up").click(
	function()
		{
            $(".delete").css("opacity", 0.5);
					$(".del").attr("checked", "");
					$(".rewrite").css("opacity", 1);
					$(".rewrite").addClass("submit");
					$(".submit").click(
						function()
							{
								$(this).parents("form").submit();
							}
					);

					$(".rewrite").removeClass("disabled");
		}
);
$(".sh").click(
	function()
		{
            $(".delete").css("opacity", 0.5);
					$(".del").attr("checked", "");
					$(".rewrite").css("opacity", 1);
					$(".rewrite").addClass("submit");
					$(".submit").click(
						function()
							{
								$(this).parents("form").submit();
							}
					);

					$(".rewrite").removeClass("disabled");
		}
);



$(".go_to_basket").click(
	function()
		{
			$(this).parents("form").attr("action", "/personal/cart/");
		}
);

$(".delete").click(
	function()
		{
			$("#act").attr("value", "del");
		}
);

$(".del").click(
	function()
		{
			$(".delete").css("opacity", 1);
			$(".delete").removeClass("disabled");
			$(".delete").addClass("submit");
            $(".submit").click(
				function()
					{
						$(this).parents("form").submit();
					}
			);
			is_checked="n";
            $(".del").each(function(i)
				{
					//alert($(this).attr("checked"));
					if ($(this).attr("checked")==true) {is_checked="y";}
				});
			if (is_checked=="n") {$(".delete").css("opacity", 0.5);};
		}
);


$(".order").click(
	function()
		{
			$("#act").attr("value", "order");
		}
);

$(".submit").click(
	function()
		{
			$(this).parents("form").submit();
		}
);



$("#select_all").click(
	function()
		{
			$(".del").attr("checked", "checked");
			$(".delete").css("opacity", 1);
			$(".delete").removeClass("disabled");
			$(".delete").addClass("submit");
			$(".submit").click(
				function()
					{
						$(this).parents("form").submit();
					}
			);
		}
);

$("#de_select_all").click(
	function()
		{
			$(".del").attr("checked", "");
			$(".delete").css("opacity", 0.5);
			$(".delete").removeClass("submit");
            $(".delete").addClass("disabled");
            $(".disabled").click(
				function()
					{
						$(this);
					}
			);
		}
);


$(".disabled").css("opacity", 0.5);



/* фотогалерея */
count=$("#fotogallery2 a").length;
$("#fotogallery2").width(count*130);


});




$(document).ready(function() {

// Скролирование
$(window).scroll(function () {
	// Инициализируем переменные
	var echo, top, wrap_h, br_h;
	// Параметры области просмотра
	window_h=$(window).height();
	// Параметры оболочки изображения
	img_wrap_h=$("#img_wrap").height();
	img_wrap_top=((window_h-img_wrap_h)/2)+$(window).scrollTop(); // Отступ сверху
	if (img_wrap_h<window_h)
		{
			//$("#img_wrap").animate ({"top": img_wrap_top}, 100);
			$("#img_wrap").css("top", img_wrap_top);
		};
});

});

// Функция показа большого изображения - вывод оболочки
function show_img (src, effect) // путь к изображению, ширина, высота, эффект: ''-без эффектов, '1'-листание больших изображений
	{
		// Инициализируем переменные
		var echo, top, wrap_h, br_h, bg_color, bg_opacity, bg_time, bg_h, window_h, window_w;

        // Параметры фона
		bg_color="#fff"; // Цвет
		bg_opacity=0.5; // Прозрачность
		bg_time=500; // Время
        bg_h=$("body").height(); // Высота

		// Параметры области просмотра
		window_h=$(window).height();
		window_w=$(window).width();

        // Фон
		echo='<div id="bg" style="background:'+bg_color+'; position:absolute; top:0; z-index:1; width:100%; height:'+bg_h+'px;" onclick="hid_img();"></div>';

		// Выводим
		$("body").append(echo);

		// Анимируем
        $("#bg").css("opacity", 0);
		$("#bg").animate
			(
				{opacity: bg_opacity},
				bg_time,
				function()
					{
                        show_big_img (src, effect); // Выводим изображение
					}
			);
	}

// Функция показа большого изображения - выводим изображение
function show_big_img (src, effect)
	{
		// Инициализируем переменные
		var echo, img_style, img_wrap_h, img_wrap_w, img_wrap_top, img_wrap_left, window_h, window_w, bg_h;

		// Стиль изображения
		img_style='style="border:solid 1px #ccc;"';

        // Параметры области просмотра
		window_h=$(window).height();
		window_w=$(window).width();

		//alert(img_wrap_left);

		// Оболочка, изображение
        echo='<div id="img_wrap" style="cursor:pointer; position:absolute; z-index:10000; top:'+img_wrap_top+'px; left:'+img_wrap_left+'px; height:'+img_wrap_h+'px; width:'+img_wrap_w+'px;">';
			echo+='<div align="right" id="img_close"><img src="/images/close.gif" alt="Закрыть" title="Закрыть"  onclick="hid_img();" /></div>';
                if (effect=='1') {echo+='<div><img id="img" '+img_style+' src="'+src+'"  onclick="next_img('; echo+="'"; echo+=src;	echo+="'"; echo+=');">'; echo+='</div>';}
                else {echo+='<div><img id="img" '+img_style+' src="'+src+'"  onclick="hid_img();"></div>';};
		echo+='</div>';

        // Выводим загрузчик //load_h=(window_h-130)/2+$(window).scrollTop(); //$("body").append('<span id="load" style="font-size:100px; color:#fff; position:absolute; top: '+load_h+'px; left:255; z-index:100;">.</span>'); //loader();

		// Выводим
		$("body").append(echo);

		// Проверяем полную загрузку изображения
        $("#img").load
			(
				function ()
					{
						// Останавливаем загрузку, удаляем таймер //clearTimeout(load);	start=0; $("#load").remove();

                        // Параметры оболочки изображения
						img_w=$("#img").width(); img_h=$("#img").height(); // Ширина, высота изображения
						img_wrap_w=img_w+20; img_wrap_h=img_h+20; // Ширина, Высота Оболочки
						img_wrap_top=(window_h-img_h)/2+$(window).scrollTop(); // Отступ сверху
						//alert($(window).scrollTop());
						img_wrap_left=(window_w-img_w)/2; // Отступ слева



						if (img_h>window_h) {img_wrap_top=$(window).scrollTop()+20; /*alert(img_wrap_top);*/} // Если высота изображения больше области просмотра

						// Изменяем параметры фона, в зависимости от размера изображения
						bg_h=$("body").height(); // Высота
						if (($(window).scrollTop()+img_h)>bg_h) {bg_h=$(window).scrollTop()+img_h+60;}; // Если высота картирки и прокрутка больше высоты фона
						$("#bg").css("height", bg_h);

						if (img_w>window_w) {
							img_wrap_left=0; img_wrap_top=0; img_wrap_h=img_h;

							$("#bg").css("height", img_wrap_h);
							$("#img_close").css("display", "none");

							}

						$("#img_wrap").css("width", img_wrap_w);
						$("#img_wrap").css("height", img_wrap_h);
						$("#img_wrap").css("top", img_wrap_top);
						$("#img_wrap").css("left", img_wrap_left);


					}
			);
	}

start=1;

function loader()
	{
		if (start==1)
			{
                load=$("#load").html();
				//alert(load.length);
				if (load.length<10) {$("#load").html(load+".");}
				else {$("#load").html(".");};
				load=setTimeout ("loader()", 500);
			}
	}

// Функция показа следующего изображения
function next_img (src)
	{
		// Обрабатываем массив изображений
		// Определяем номер текущего изображения
		var i=0;
        while (arImages[i]!=src) {i++;}
		i=i+1;
		if (i==arImages.length) {i=0;}
		$("#img_wrap").remove();
		show_big_img (arImages[i], '1');
	}

// Функция скрытия большого изображения
function hid_img ()
	{
		var time=500;
        $("#img_wrap").animate({opacity: 0},time,
			function()
					{
                        $("#img_wrap").remove();
					}
			);
        $("#bg").animate({opacity: 0},time,
			function()
					{
						$("#bg").remove();
					}
			);

	}

function flash(src, w, h, alt) {
var flash='';
flash = flash + '<object type="application/x-shockwave-flash" width=' + w + ' height=' + h + ' data=' + src + '>';
flash = flash + '<param value=' + src + ' name="movie" />';
flash = flash + '<param name="WMode" VALUE="Transparent" />';
flash = flash + alt;
flash = flash + '</object>';

document.write(flash);
}

$(document).ready(function() {

$(".text").keypress(function(event){
if (event.keyCode==13) {$(this).parents("FORM").submit();};
//alert("asdf");
});

});



