$(document).ready(function() {
	if ($('#up a')[0] != undefined ) {
		$('#up a').click(function(event){
			if (window.opera) $('html').animate({scrollTop:0}, 'slow');
			else $('html, body').animate({scrollTop:0}, 500);
			event.preventDefault();
		});
	}
	//$('.container:first').snowfall({shadow : true, round : true,  minSize: 3, maxSize:5, flakeCount:42});
});

/* Для строки поиска { */
var srch = {
	clk: function(obj) {
		if (obj) {
			if (obj.alt == 0 && obj.value == 'Поиск по сайту') {
				obj.value = '';
				obj.alt = 1;
				obj.style.color="#000";
			}
		} else
			alert('id не передан');
	},
	blr: function(obj) {
		if (obj) {
			if (obj.alt == 1 && obj.value == '') {
				obj.value = 'Поиск по сайту';
				obj.alt = 0;
				obj.style.color="#b4b0b0";
			}
		} else
			alert('id не передан');
	}
};
/*var helpHelp = {
	store:new Array,
	clk: function(obj, helpText) {
		if (obj) {
			if (obj.rev == undefined) {
				if (obj.alt == '') {
					this.store.push(obj.value);
					obj.alt = this.store.length-1;
				}
				obj.rev = 0;
			}
			if (obj.rev == 0 && obj.value == this.store[obj.alt]) {
				obj.value = '';
				obj.rev = 1;
				obj.style.color="#000";
			}
		} else
			alert('id не передан');
	},
	blr: function(obj, helpText) {
		if (obj) {
			if (obj.rev == 1 && obj.value == '') {
				obj.value = this.store[obj.alt];
				obj.rev = 0;
				obj.style.color="#b4b0b0";
			}
		} else
			alert('id не передан');
	}
};*/
var helpHelp = {
	store:new Array,
	clk: function(obj, helpText) {
		//alert(obj.value+" <> "+helpText)
		if (obj) {
			//alert("есть obj");
			if (obj.rev == undefined) {
				if (obj.alt == '' || obj.alt == undefined) {
					//alert("регистрируем alt");
					this.store.push(helpText);
					obj.alt = this.store.length-1;
					//alert("alt = "+obj.alt);
				}
				//alert("регистрируем rev");
				obj.rev = 0;
				//alert("rev = "+obj.rev);
			}
			//alert("obj.value = this.store[obj.alt]: "+(obj.value = this.store[obj.alt]))
			if (obj.rev == 0 && obj.value == this.store[obj.alt]) {
				obj.value = '';
				obj.rev = 1;
				obj.style.color="#000";
			} else {
				obj.rev = 1;
			}
		} else
			alert('id не передан');
	},
	blr: function(obj) {
		if (obj) {
			if (obj.rev == 1 && obj.value == '') {
				obj.value = this.store[obj.alt];
				obj.rev = 0;
				obj.style.color="#b4b0b0";
			}
		} else
			alert('id не передан');
	}
};
/* Для строки поиска } */

/*var submenu = {
	state: new Array(),
	wait_time: 0,
	autoclose: true,
	elems: new Array(),
	obj_this: new Array(),
	elemNum: 0,
	scanDOM: function(obj, keyClassName, subClassName) {
		var childs = obj.childNodes;
		for (var i = 0; i<childs.length; i++) {
			if (childs[i].nodeType == 1) {
				if (childs[i].className.match(new RegExp(keyClassName,"ig")) ||
					childs[i].className.match(new RegExp(subClassName,"ig"))) {
					this.elems.push(new Array(this.elemNum,childs[i]));
					childs[i].num = (this.elemNum++);
				} else
					this.scanDOM(childs[i], keyClassName, subClassName);
			}
		}
		return 0;
	},
	getElemByNum: function(num) {
		for (var i=0; i<this.elems.length; i++) {
			if (this.elems[i][0] == num) {
				return this.elems[i][1];
			}
		}
	},
	addEvent: function (obj, event, func) {
		if (obj.addEventListener)
			obj.addEventListener(event, func, false);
		else {
			obj['e' + event + func] = func;
			obj[event+func] = function() { obj['e' + event + func](window.event); };
			obj.attachEvent('on' + event, obj[event + func]);
		}
	},
	init: function(obj, exp) {
		obj = document.getElementById(obj);
		exp = exp.replace(/[ ]/ig,'').split(/[<]/);
		this.scanDOM(obj, exp[0], exp[1]);
		obj = this.elems;
		for (var i=0; i<obj.length; i+=2) {
			if (obj[i]) {
				this.state[obj[i][1].num] = 0;
				this.obj_this[obj[i][1].num] = new Array();
				this.addEvent(obj[i][1], 'mouseover', function (){submenu.open(this)} );
				this.addEvent(obj[i][1], 'mouseout', function (){submenu.closequery(this)} );
				if (obj[i+1][1]) {
					this.obj_this[obj[i][1].num]['child'] = obj[i+1][1];
					this.addEvent(obj[i+1][1], 'mouseover', function (){submenu.open(this)} );
					this.addEvent(obj[i+1][1], 'mouseout', function (){submenu.closequery(this)} );
				}
				else {
					alert('[submenu.init] Ошибка при инициализации дочернего объекта "'+obj[i+1][1]+'"');
				}
			} else
				alert('[submenu.init] Ошибка при инициализации объекта "'+obj[i][1]+'"');
		}
	},
	open: function(obj) {
		obj = (obj.num%2==0)?this.getElemByNum(obj.num):this.getElemByNum(obj.num-1);
		if (this.state[obj.num] == 0) {
			this.state[obj.num] = 1;
			this.obj_this[obj.num]['open'] = true;
			this.obj_this[obj.num]['qclose'] = false;
			this.obj_this[obj.num]['time'] = this.wait_time;
			this.obj_this[obj.num]['child'].style.display="block";
			if (!obj.parentNode.className.match(/(^select$)|( select$)/))
				obj.parentNode.className += " mselect";
		} else
		if (this.state[obj.num] == 2) {
			this.state[obj.num] = 1;
			this.obj_this[obj.num]['qclose'] = false;
			this.obj_this[obj.num]['time'] = this.wait_time;
			if (this.wait_time > 0)
				clearInterval(this.obj_this[obj.num]['interval']);
			if (!obj.parentNode.className.match(/(^select$)|( select$)/))
				obj.parentNode.className += " mselect";
		}
	},
	closequery: function(obj) {
		obj = (obj.num%2==0)?this.getElemByNum(obj.num):this.getElemByNum(obj.num-1);
		if (this.obj_this[obj.num]['qclose'] == false && this.state[obj.num] == 1) {
			this.state[obj.num] = 2;
			this.obj_this[obj.num]['qclose'] = true;
			if (this.wait_time > 0)
				this.obj_this[obj.num]['interval'] = setInterval("submenu.close('"+obj.num+"')",100);
			else
				submenu.close(obj.num);
			obj.parentNode.className = obj.parentNode.className.replace(/mselect/ig,'').replace(/ $/,'');
		}
	},
	close: function(obj) {
		obj = this.getElemByNum(obj);
		if (this.state[obj.num] == 2 && this.obj_this[obj.num]['qclose'] == true && this.obj_this[obj.num]['time'] > 1) {
			this.obj_this[obj.num]['time']-- ;
		} else
		if (this.state[obj.num] == 2 && this.obj_this[obj.num]['qclose'] == true) {
			if (this.wait_time > 0)
				clearInterval(this.obj_this[obj.num]['interval']);
			this.state[obj.num] = 0;
			this.obj_this[obj.num]['child'].style.display="none";
		}
	}
};*/
	/*submenu.init('menu', 'case < submenu');*/


/* Обработка select sizeble { */
var select_size = {
	is_open: false,
	state: false,
	oc_list: function(self, obj) {
		obj = document.getElementById(obj);
		$("div.select-size-open").css({'display':'none'});
		obj.style.display = (obj.style.display=='' || obj.style.display=='none')?'block':'none';
		select_size.is_open = true;
		select_size.state = false;
		/*if ($.browser.className == 'msie6' || $.browser.className == 'msie7') {
			$("form.filter > *").css({'z-index':'-1'});
			$(".filter input[type='submit']").css({'z-index':'-2'});
			self.style.zIndex = 1;
		}*/
		/*kostya*/
		//obj.style.width = parseInt(self.offsetWidth)+'px';
		obj.style.minWidth = parseInt(self.offsetWidth)+'px';
		if (Math.abs(parseInt(obj.offsetWidth) - parseInt(self.offsetWidth)) != 0) {
			//alert('obj.style.width = '+(parseInt(self.offsetWidth) - Math.abs(parseInt(obj.offsetWidth) - parseInt(self.offsetWidth)))+'px');
			/*kostya*/
			//obj.style.width = (parseInt(self.offsetWidth) - Math.abs(parseInt(obj.offsetWidth) - parseInt(self.offsetWidth)))+'px';
			obj.style.minWidth = (parseInt(self.offsetWidth) - Math.abs(parseInt(obj.offsetWidth) - parseInt(self.offsetWidth)))+'px';
		}
	},
	change: function(selname,val,text) {
		$("div.select-size-open").css({'display':'none'});
		div = $($("div#text_"+selname)[0]);
		div.html((text.replace(/<em>/,'').replace(/<\/em>/,'').replace(/: /,': <b>')+"</b>").replace(/<b>не важно<\/b>/ig, "не важно"));
		selname = document.getElementById(selname);
		selname.value = val;//.replace(/"/, "&quot;");
		option = $(selname).find("option:selected");
		div.css("color", option.attr("rel") ? option.attr("rel") : "#555");
		if (selname.onchange) selname.onchange();
		select_size.is_open = false;
		/*if ($.browser.className == 'msie6' || $.browser.className == 'msie7') {
			$("form.filter > *").css({'z-index':'1'});
			$(".filter input[type='submit']").css({'z-index':'1'});
		}*/
	}
}
$(document).ready(function() {
	$(document).bind("click", function(e) {
		if (select_size.is_open) {
			if (select_size.state) {
				$("div.select-size-open").css({'display':'none'});
				/*if ($.browser.className == 'msie6' || $.browser.className == 'msie7') {
					$("form.filter > *").css({'z-index':'1'});
					$(".filter input[type='submit']").css({'z-index':'1'});
				}*/
				select_size.is_open = false;
				select_size.state = false;
			} else
				select_size.state = true;
		}
	});
	initSelect();
	initPlateSwitch();
	$('.footer .rightpart').css('height',$('.footer .mainpart').height());
	/*setTimeout(function() {
		reCreateSelect("s3");
	}, 1000);*/
});

function initSelect() {
	var tpl = '	<div class="select-size" onclick="select_size.oc_list(this, \'{OPEN_ID}\')">';
		tpl+= '		<div class="target">&nbsp;</div>';
		tpl+= '		<div class="select-field">';
		tpl+= '			<div>';
		tpl+= '				<div id="{TEXT_ID}"{COLOR}>{SELECT_TEXT}</div>';
		tpl+= '			</div>';
		tpl+= '		</div>';
		tpl+= '	</div>';
		tpl+= '	<div id="{OPEN_ID}" class="select-size-open">';
		tpl+= '		<div class="canva">';
		tpl+= '			<div class="plane">';
		tpl+= '				<div class="t-left">';
		tpl+= '					<div class="t-right">';
		tpl+= '						<div class="b-left">';
		tpl+= '							<div class="b-right">';
		tpl+= '								<div class="lr-bord">';
		tpl+= '									<div class="inner">';
		tpl+= '										{OPTION}';
		tpl+= '									</div>';
		tpl+= '								</div>';
		tpl+= '							</div>';
		tpl+= '						</div>';
		tpl+= '					</div>';
		tpl+= '				</div>';
		tpl+= '			</div>';
		tpl+= '		</div>';
		tpl+= '	</div>';

	var opttpl = '<div><a href="javascript:select_size.change(\'{SELECT_NAME}\',\'{VAL}\',\'{HTML}\')"><span><span{COLOR}>{HTML}</span></span></a></div>';

	//$("select").css({'display':'none'});
	//$("select").attr("init","inited");

	for (var i=0; i<$("select").length; i++) { /* { бежим по selectам } */
		if ($($("select")[i]).css("display") != 'none') {
			$($("select")[i]).css({"display":'none'});
			var	opttplcopy = '';
			for (var f=0; f<$($("select")[i]).find("option").length; f++ ) {
				option = $($($("select")[i]).find("option")[f]);
			
				
				if (/.*(\: ).*/.test(option.html())) {
					opttplcopy+= opttpl.replace(/{ID}/ig, $("select")[i].name+"_opt"+f)
						.replace(/{HTML}/ig, '<em>' + option.html().replace(/"/ig, '&quot;').replace(/'/ig, '&apos;').replace(/: /,': </em>'))
						.replace(/{VAL}/ig, option.val().replace(/"/, '&quot;').replace(/'/, '&apos;'))
						.replace(/{SELECT_NAME}/ig, $("select")[i].name)
						.replace(/{COLOR}/ig, option.attr("rel") ? ' style="color: ' + option.attr("rel") + ';"' : "");
				} else {
					opttplcopy+= opttpl.replace(/{ID}/ig, $("select")[i].name+"_opt"+f)
						.replace(/{HTML}/ig, option.html().replace(/"/ig, '&quot;').replace(/'/ig, '&apos;'))
						.replace(/{VAL}/ig, option.val().replace(/"/ig, '&quot;').replace(/'/ig, '&apos;'))
						.replace(/{SELECT_NAME}/ig, $("select")[i].name)
						.replace(/{COLOR}/ig, option.attr("rel") ? ' style="color: ' + option.attr("rel") + ';"' : '');
				}
			}
			var tplcopy = tpl.replace(/{SELECT_TEXT}/ig, $($("select")[i]).find('option:selected').html().replace(/: /,': <b>')+"</b>")
				.replace(/<b>не важно<\/b>/ig, "не важно")
				.replace(/{OPTION}/ig, opttplcopy)
				.replace(/{OPEN_ID}/ig, "open_"+$("select")[i].name)
				.replace(/{TEXT_ID}/ig, "text_"+$("select")[i].name)
				.replace(/{COLOR}/ig, $($("select")[i]).find('option:selected').attr("rel") ? ' style="color: ' + $($("select")[i]).find('option:selected').attr("rel") + ';"': "");
			//alert(tplcopy);
			//alert(tplcopy);
			$($("select")[i]).after($(tplcopy));
			//alert($('select name="'+select[i][0]+'"').name);
		}
	}
	//alert(1);
}

function reCreateSelect(id) {
	$("#"+id).css({"display":'block'});
	$("#"+id).next().remove();
	$("#open_"+id).remove();
	initSelect();
}
/* Обработка select } */

/* Пересчёт колонок { */
function resizeTable() {

	var dl = $("div.alldetile div.cols dl");
	var sumHeight = 0;
	var blockWidth = 0;
	var parrentWidth = 0;
	var cols = 0;
	var logHeightCols = 0;

	blockWidth = $($("div.alldetile div.cols dl")[0]).width();
	parrentWidth = $("div.alldetile div.cols").width();
	cols = parseInt(parrentWidth / blockWidth);
	cols = parseInt((parrentWidth - (140+(cols*20))) / blockWidth);
	//alert("Колонок: "+cols+" | parseInt("+parrentWidth+"/"+blockWidth+")");
	if (cols != $pre_cols) {
		$pre_cols = cols;
		$("div.alldetile div.cols div dl").unwrap();

		$("div.alldetile div.cols dl").css({"float":"none"});

		for (var i=0; i<dl.length; i++) {
			sumHeight += dl[i].offsetHeight;
		}

		logHeightCols = Math.round(((sumHeight/cols)));

		i = 0;
		for (var c=0; c<cols; c++) {
			sumHeight = 0;
			logics = 0;
			while (sumHeight < logHeightCols && i<dl.length) {
				if (sumHeight + dl[i].offsetHeight > logHeightCols) {
					logics = (sumHeight + dl[i].offsetHeight) - logHeightCols;
					if (logics > (logHeightCols - sumHeight))
						break;
				}
				sumHeight += dl[i].offsetHeight;
				$($("div.alldetile div.cols dl")[i]).addClass('col'+c);
				i++;
			}
			$('div.alldetile div.cols dl.col'+c).wrapAll('<div />');
			$('div.alldetile div.cols dl.col'+c).removeClass('col'+c);
		}
		$('div.alldetile div.cols div').css({"float":"left"});
	}
}
$(document).ready(function() {
	$pre_cols = 0;
	if ($.browser.className != 'msie6') {
		setTimeout(function() {
			$('.pre-footer').css('height', 0);
			$('.pre-footer').css('height', $('.footer').height());
			$('.footer').css('width', $('.container').width()-68);
			$('.footer .rightpart').css('height',$('.footer .mainpart').height());
			resizeTable();
			
			$(window).resize(function() {
				resizeTable();
				$('.pre-footer').css('height', 0);
				$('.pre-footer').css('height', $('.footer').height());
				$('.footer').css('width', $('.container').width()-68);
				$('.footer .rightpart').css('height',$('.footer .mainpart').height());
				/*if ($.browser.className == 'msie6') {
					setTimeout( function() {
						$('.footer').css('left', '-1px');
						$('.footer').css('left', '0px');
					}, 1000)
				}*/
			});

		}, 300);
	}
});
/* Пересчёт колонок } */




$(document).ready(function() {
	var subpage = (unescape(self.document.location.hash.substring(1)) == '')?'short-descript':unescape(self.document.location.hash.substring(1));
	subpage = (subpage != 'short-descript' && subpage != 'full-descript' && subpage != 'detail' && subpage != 'color-select')?'short-descript':subpage;

	$(".tabscnt").css({"display":"none"});
	$(".alldetile ."+subpage).css({"display":"block"});

	if (subpage == 'detail')
		$(".detailinit").css({"display":"none"});
	else
	if (subpage == 'short-descript')
		$(".alldetile .short-descriptinit").css({"text-decoration":"none","cursor":"default"});
	else
	if (subpage == 'full-descript')
		$(".alldetile .full-descriptinit").css({"text-decoration":"none","cursor":"default"});
	else
	if (subpage == 'color-select') {
		$("#emptydiv").hide();
		$(".alldetile .color-selectinit").css({"text-decoration":"none","cursor":"default"});
	}

	function openTab(name) {
		name = name.replace(/init/,'');
		if (name != subpage) {
			self.location.href='#'+name;
			subpage = name;
			$(".tabscnt").fadeOut(100);
			setTimeout(function() {
				$(".alldetile ."+name).fadeIn(100);
				resizeTable();
			},120);

			if (name == 'detail')
				$(".detailinit").fadeOut(100);
			else {
				$(".detailinit").css({"text-decoration":"underline","cursor":"pointer"});
				$(".detailinit").fadeIn(100);
			}
			if (name == 'short-descript')
				$(".short-descriptinit").css({"text-decoration":"none","cursor":"default"});
			else
				$(".short-descriptinit").css({"text-decoration":"underline","cursor":"pointer"});
			if (name == 'full-descript')
				$(".full-descriptinit").css({"text-decoration":"none","cursor":"default"});
			else
				$(".full-descriptinit").css({"text-decoration":"underline","cursor":"pointer"});
			if (name == 'color-select') {
				$("#emptydiv").hide();
				$(".color-select").css({"text-decoration":"none","cursor":"default"});
			}
			else
				$(".color-select").css({"text-decoration":"underline","cursor":"pointer"});
		}
	}

	$(".tabsinit").each(function(i) {
		$(this).bind('click',function(){
			var selpage = $(this)[0].className.match(/([a-zA-Z_\-]*)init/ig);
			openTab(selpage[1]);
		})
		$(this).bind('mouseover',function(){
			$(this).css({"text-decoration":"none"});
		})
		$(this).bind('mouseout',function(){
			var selpage = $(this)[0].className.match(/([a-zA-Z_\-]*)init/ig);
			if (subpage != selpage[1].replace(/init/,'')) {
				$(this).css({"text-decoration":"underline"});
			}
		})
	})
	
	if ($(".full-descriptinit")[0] != undefined)
		if ($(".short-descriptinit")[0] == undefined) {
			openTab("full-descriptinit");
		}

	/*-*/

	$(".tovar-text-one").hide();
	var noTovarTextClose = true;
	var noTovarTextIsShow = false;
	function closeNoTovarText() {
		if (noTovarTextIsShow == true) {
			setTimeout(function(){
				if (noTovarTextClose == true) {
					$(".tovar-text-one").fadeOut("fast");
					noTovarTextIsShow = false;
				}
			},2000);
		}
	}
	$(".tovar-text-open").bind('mouseover',function(){
		noTovarTextClose = false;
		if (noTovarTextIsShow == false) {
			$(".tovar-text-one").fadeIn("fast");
			noTovarTextIsShow = true;
		}
	})
	$(".tovar-text-open").bind('mouseout',function(){
		noTovarTextClose = true;
		closeNoTovarText();
	})
	$(".tovar-text-one").bind('mouseover',function(){
		noTovarTextClose = false;
	})
	$(".tovar-text-one").bind('mouseout',function(){
		noTovarTextClose = true;
		closeNoTovarText();
	})

	/*-*/
	$(".good-group .acsesuar .text div a").each(function(i){
		$(this).bind('mouseover', function(){
			$($(".good-group .acsesuar .info .info-contaner")[i]).fadeIn("fast");
		})
		$(this).bind('mouseout', function(){
			$($(".good-group .acsesuar .info .info-contaner")[i]).fadeOut("fast");
		})
	})
	/*$(".good-group .acsesuar .info .info-contaner").fadeIn("fast");*/


});

/* { bpanel */
$(document).ready(function() {
	if ($('.bottom-motion-panel')[0] != undefined) {
		if (!$.cookie("bottomPanelClose")) {
			$.cookie("bottomPanelClose", 'close');
		}

		var bottomPanelClose = $.cookie("bottomPanelClose");

		if ($.cookie("bottomPanelClose")) {
			if (bottomPanelClose == 'close')
				$('.bottom-motion-panel .content-show-hide').hide();
			else
				$('.bottom-motion-panel .content-show-hide').show();
		} else {
			bottomPanelClose = 'close'
			$('.bottom-motion-panel .content-show-hide').hide();
		}
		$('.bottom-motion-panel .motion-button span').addClass(bottomPanelClose);

		$('.bottom-motion-panel .motion-button').click(function(event){
			$('.bottom-motion-panel .content-show-hide').slideToggle("fast");
			$('.bottom-motion-panel .motion-button span').removeClass(bottomPanelClose);
			bottomPanelClose = (bottomPanelClose == 'close')?'open':'close';
			$('.bottom-motion-panel .motion-button span').addClass(bottomPanelClose);
			$.cookie("bottomPanelClose", bottomPanelClose);
		});
	}
});
function comparePanelShow() {
	var bottomPanelClose = $.cookie("bottomPanelClose");
	if (bottomPanelClose == 'close') {
		$('.bottom-motion-panel').fadeIn("fast",function(){
			$('.bottom-motion-panel .motion-button').click();
		});
	} else
		$('.bottom-motion-panel').fadeIn("fast");
}
function comparePanelHide() {
	var bottomPanelClose = $.cookie("bottomPanelClose");
	if (bottomPanelClose == 'close')
		$('.bottom-motion-panel').fadeOut("fast");
	else {
		$('.bottom-motion-panel .motion-button').click();
		setTimeout(function(){
			$('.bottom-motion-panel').fadeOut("fast");
		},200);
	};
}
/* } bpanel*/

$(document).ready(function() {
	var groupWidth = 0;
	setTimeout(function(){
		if ($('.product-description')[0] != undefined) {
			if ($('.product-description .control .load-img a')[0] != undefined) {
				groupWidth = (parseInt($('.product-description .control .load-img a').css("margin-right"))+parseInt($('.product-description .control .load-img a').css("width")))*3;
			}
			if ($('.product-description .control .load-img div')[0] != undefined) {
				$('.product-description .control .load-img div').css({
					"width":((parseInt($('.product-description .control .load-img a').css("margin-right"))+parseInt($('.product-description .control .load-img a').css("width")))*$('.product-description .control .load-img a').length)+"px"
				});
			}
			var loadingProcess = false;
			if ($('.product-description .preview img')[0] != undefined) {
				$('.product-description .preview img').load(function(){
					$('.product-description .preview img').fadeTo("fast",1,function() {
						loadingProcess = false;
					});
				})
			}
			if ($('.product-description .control .load-img a')[0] != undefined) {
				$('.product-description .control .load-img a').each(function(i){
					$(this).css({"background-image":"url("+$(this)[0].rev+")"});
					$(this)[0].rev = $(this)[0].href;
					$(this)[0].href = 'javascript:void(0)';

					$(this).click(function(event){
						if (!$(this).hasClass('select')) {
							if (loadingProcess == false) {
								$('.product-description .control .load-img a').removeClass('select');
								if ($(this)[0].rev != $('.product-description .preview img')[0].src) {
									loadingProcess = true;
									$('.product-description .preview img')[0].rev=$(this)[0].rev;
									$('.product-description .preview img')[0].alt=$(this)[0].title;
									$('.product-description .preview img').fadeTo("fast",0.001,function(){
										if ($('.product-description .preview img')[0].rev != 0 ) {
											$('.product-description .preview img')[0].src=$('.product-description .preview img')[0].rev;
											$('.product-description .preview img')[0].rev = 0;
										}
									});
								}
								$(this).addClass('select');
							}
						}
					})
					if (i==0) {
						$(this).addClass('select');
						$('.product-description .preview img')[0].src=$(this)[0].rev;
						$('.product-description .preview img')[0].alt=$(this)[0].title;
					}
				})
			}
			if ($('.product-description .control .next')[0] != undefined && $('.product-description .control .back')[0] != undefined) {
				$('.product-description .control .next').click(function(event){
					var showWidth = parseInt($('.product-description .control .load-img div').css("left"))+$('.product-description .control .load-img div').width();
					var lastPosition = parseInt($('.product-description .control .load-img div').css("left"));
					if (showWidth - groupWidth > 0 &&
						lastPosition % groupWidth == 0)
						$('.product-description .control .load-img div').animate({"left":lastPosition - groupWidth + "px"});
				})
				$('.product-description .control .back').click(function(event){
					var showWidth = parseInt($('.product-description .control .load-img div').css("left"))+$('.product-description .control .load-img div').width();
					var lastPosition = parseInt($('.product-description .control .load-img div').css("left"));
					if (lastPosition < 0 &&
						lastPosition % groupWidth == 0)
						$('.product-description .control .load-img div').animate({"left":lastPosition + groupWidth + "px"});
				});
			}
		}
	},10);
})

function showAjaxMessage(infCode) {
	var controller = $('<input id="windows-info" type="button" value="'+infCode+'" class="widow-0x0" style="display: none;" />');
	controller.appendTo("body");
	$("#windows-info").fancybox({
		'hideOnOverlayClick': false,
		'width'				: 250,
		'height'			: 200,
		'autoScale'     	: true,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'scrolling'			: 'no',
		'type'				: 'ajax',
		onStart				: function() {
			$("#fancybox-close").css({"top":"-8px"})
		},
		onComplete			: function() {
			setTimeout(function(){
				//$.fancybox.resize();
				if ($.browser.className == 'msie6') {
					$('#fancybox-inner').width($('.info-window').width());
					$('#fancybox-inner').height($('.info-window').height()+30);
					$('#fancybox-wrap').width($('.info-window').width()+40);
					$('#fancybox-wrap').height($('.info-window').height()+65);
					//($.browser.className == 'msie6')?(width+41):width;
				}
				//$.fancybox.center();
				initRadioBox();
				initCheckBox();
			},10)
		}
	});
	controller.click();
	controller.remove();
}

function showMessage(Message) {
	if ($("#showMessage").length) {
		$("#showMessage").html(Message);
		initRadioBox();
		initCheckBox();
		$.fancybox.resize();
		return false;
	}
	var controller = $('<a id="windows-info-loc" href="#showMessage" style="display: none">0</a>');
	var content = $('<div id="showMessage" class="info-window">'+Message+'</div>');
	controller.appendTo("body");
	content.appendTo("body");

	$("#windows-info-loc").fancybox({
		'hideOnOverlayClick': false,
		'width'				: 250,
		'height'			: 200,
		'autoScale'     	: true,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		onStart				: function() {
			$("#fancybox-close").css({"top":"-8px"});
		},
		onClosed			: function() {
			content.remove();
		},
		onComplete			: function() {
			setTimeout(function(){
				$.fancybox.resize();
				$.fancybox.center();
				initRadioBox();
				initCheckBox();
				initSelect();
			},10)
		}
	});
	controller.click();
	controller.remove();
	if ( $('.filter-drag').length ) {
		$('.filter-drag').each( function() {
			var $this = $(this);
			var thisGrid = 0;
			var startGrid = parseInt($this.parents('.credit-filter:first').find('.filter-start:first').html());
			var stopGrid = parseInt($this.parents('.credit-filter:first').find('.filter-stop:first').html());
			if ( $this.hasClass('drag-percent') ) {
				thisGrid = parseInt(160 / (rsDeposits.length - 1));
			} else {
				thisGrid = parseInt(160 /( stopGrid - startGrid));
			}
			$this.draggable({
				axis: 'x',
				grid: [thisGrid,0],
				containment: $this.parents('.credit-filter:first'),
				drag: function() {
					$this.parents('.credit-filter:first').find('.filter-line div:first').css({width: parseInt($this.css('left'))+'px'});
					if ( $this.hasClass('drag-percent') ) {
						$this.parents('.credit-calc:first').find('.credit-percent:first').html( rsDeposits[Math.round(parseInt($this.css('left')) * (rsDeposits.length - 1) /160)] );
					} else {
						$this.parents('.credit-calc:first').find('.credit-period:first').html( parseInt(parseInt($this.css('left'))*(stopGrid - startGrid)/160 + startGrid) );
					}
					var monthPay = $this.parents('.credit-calc:first').find('.credit-cost:first').html() * rsCredit[$this.parents('.credit-calc:first').find('.credit-period:first').html()][$this.parents('.credit-calc:first').find('.credit-percent:first').html()];
					monthPay = parseInt(monthPay * 100) / 100;
					$this.parents('.credit-calc:first').find('.month-pay:first').html( Math.round(monthPay) );
					var totalPay = $this.parents('.credit-calc:first').find('.credit-cost:first').html() / 100 * $this.parents('.credit-calc:first').find('.credit-percent:first').html() + monthPay * $this.parents('.credit-calc:first').find('.credit-period:first').html();
					$this.parents('.credit-calc:first').find('.total-pay:first').html( Math.round(totalPay) );
					var overPay = totalPay - $this.parents('.credit-calc:first').find('.credit-cost:first').html();
					$this.parents('.credit-calc:first').find('.over-pay:first').html( Math.round(overPay) );
				},
				stop: function() {
					if ( parseInt($this.css('left'))>161 ) $this.css({left: '161px'});
					if ( parseInt($this.css('left'))<0 ) $this.css({left: '0'});
					$this.parents('.credit-filter:first').find('.filter-line div:first').css({width: parseInt($this.css('left'))+'px'});
					if ( $this.hasClass('drag-percent') ) {
						$this.parents('.credit-calc:first').find('.credit-percent:first').html( rsDeposits[Math.round(parseInt($this.css('left')) * (rsDeposits.length - 1) /160)] );
					} else {
						$this.parents('.credit-calc:first').find('.credit-period:first').html( parseInt(parseInt($this.css('left'))*(stopGrid - startGrid)/160 + startGrid) );
					}
					var monthPay = $this.parents('.credit-calc:first').find('.credit-cost:first').html() * rsCredit[$this.parents('.credit-calc:first').find('.credit-period:first').html()][$this.parents('.credit-calc:first').find('.credit-percent:first').html()];
					monthPay = parseInt(monthPay * 100) / 100;
					$this.parents('.credit-calc:first').find('.month-pay:first').html( Math.round(monthPay) );
					var totalPay = $this.parents('.credit-calc:first').find('.credit-cost:first').html() / 100 * $this.parents('.credit-calc:first').find('.credit-percent:first').html() + monthPay * $this.parents('.credit-calc:first').find('.credit-period:first').html();
					$this.parents('.credit-calc:first').find('.total-pay:first').html( Math.round(totalPay) );
					var overPay = totalPay - $this.parents('.credit-calc:first').find('.credit-cost:first').html();
					$this.parents('.credit-calc:first').find('.over-pay:first').html( Math.round(overPay) );
				}
			});
		});
	}
}

function showMessageCloseEvent(Message, onClose) {
	if ($("#showMessage").length) {
		$("#showMessage").html(Message);
		initRadioBox();
		initCheckBox();
		$.fancybox.resize();
		return false;
	}
	var controller = $('<a id="windows-info-loc" href="#showMessage" style="display: none">0</a>');
	var content = $('<div id="showMessage" class="info-window">'+Message+'</div>');
	controller.appendTo("body");
	content.appendTo("body");

	$("#windows-info-loc").fancybox({
		'hideOnOverlayClick': false,
		'width'				: 250,
		'height'			: 200,
		'autoScale'     	: true,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		onStart				: function() {
			$("#fancybox-close").css({"top":"-8px"});
		},
		onClosed			: function() {
			content.remove();
			onClose();
		},
		onComplete			: function() {
			setTimeout(function(){
				$.fancybox.resize();
				$.fancybox.center();
				initRadioBox();
				initCheckBox();
			},10)
		}
	});
	controller.click();
	controller.remove();
}

/**/
$(document).ready(function() {
	var theme = unescape(self.document.location.hash.substring(1));
	
	var backinit = 0;
	if ($(".back-form")[0] != undefined ) {
		$(".back-form #open_theme .inner div").each(function(i){
			//alert('инициализация '+i);
			$(this).click(function(){
				$("#feedbackline").show();
				$("#feedbacksend").show();
				if (++backinit == 1) {
					//$(this).parent().parent().parent().parent().parent().parent().parent().parent().parent().prev().slideUp("fast");
					//$(this).parent().parent().parent().parent().parent().parent().parent().parent().parent().prev().prev().prev().slideUp("fast");
				}
				$(".back-form .subforms").css({"display":"none"});
				$(".back-form .type"+i).css({"display":"block"});
				$(".back-form .form"+i).css({"display":"block"});
			});
			//$(this).change();
		});
		if (theme) {
			var div = $($(".back-form #open_theme .inner div")[theme]);
			div.click();
			select_size.change("theme", div.find("a")[0].href.substr(39, 3), div.find("a span span").html());
		} else {
			$($(".back-form #open_theme .inner div")[$('.back-form #theme option:selected').val()]).click();
		}
	}
	if ($(".recycle")[0] != undefined ) {
		$(".recycle #open_theme .inner div").each(function(i){
			//alert('инициализация '+i);
			var code = $(".recycle #theme option")[i].value;
			$(this).click(function(){
				$(".recycle .subforms").css({"display":"none"});
				$(".recycle .type"+code).css({"display":"block"});
				$(".recycle .form"+code).css({"display":"block"});
			});
			//$(this).change();
		});

		if ($('.recycle #theme option:selected').length) {
			$($(".recycle #open_theme .inner div")[$('.recycle #theme option:selected')[0].index]).click();
		}
	}
});
/**/
$(document).ready(function() {
	initRadioBox();
	initCheckBox();
});
function initRadioBox() {
	if ($(".radio-group")[0] != undefined ) {
		$(".radio-group input").each(function(i){

			if ($(this).css("display") != 'none') {
				$(this).css({"display":"none"});

				$(this).after($('<div id="'+($(this)[0].name+'-element'+i)+'" class="decore-point"></div>'));
				$(this).parent().after('<div class="spacer"><!-- --></div>');
				$(this).css({"display":"none"});
				$($(this).parent().find("span")).css({
					"position":"relative",
					"top":"2px"
				});
				$(this).parent().click(function(){
					$(this).parent().find("div").removeClass('select');
					$(this).find("div").addClass('select');
				});
				if ($(this).attr('checked'))
					$(this).parent().find("div").addClass('select');
			}
		});
	}
}
function initCheckBox() {
	if ($("label input:checkbox")[0] != undefined) {
		$("label input:checkbox").each(function(i){
			if ($(this).parent().css("display") != 'none') {
				$(this).parent().after($('<div class="checkbox" id="'+($(this)[0].name)+'"><div class="decore-point"></div><div class="check-text"></div></div>'));
				$(this).parent().next().css({
					"cursor":"pointer"
				})
				$(this).parent().next().click(function(){
					if (!$(this).prev().find("input:checkbox").attr('checked')) {
						$(this).find(".decore-point").addClass('select');
						$(this).prev().find("input:checkbox").attr('checked', 'checked');
					} else {
						$(this).find(".decore-point").removeClass('select');
						$(this).prev().find("input:checkbox").removeAttr('checked');
					}
				})
				if ($(this).attr('checked'))
					$(this).parent().next().find(".decore-point").addClass('select');
				$(this).parent().next().find(".check-text").text( $(this).parent().text());
				$(this).parent().css({"display":"none"})
			}
		})
	}
}

/*$(document).ready(function() {
	$("label input:checkbox").each(function(i){
		$(this).parent().after($('<div class="checkbox" id="'+($(this)[0].name)+'"><div class="decore-point"></div><div class="check-text"></div></div>'));
		$(this).parent().next().css({
			"cursor":"pointer"
		})
		$(this).parent().next().click(function(){
			if (!$("label input[name="+$(this)[0].id+"]").attr('checked')) {
				$(this).find(".decore-point").addClass('select');
				$("label input[name="+$(this)[0].id+"]").attr('checked', 'checked');
			} else {
				$(this).find(".decore-point").removeClass('select');
				$("label input[name="+$(this)[0].id+"]").removeAttr('checked');
			}
		})
		if ($(this).attr('checked'))
			$(this).parent().next().find(".decore-point").addClass('select');
		$(this).parent().next().find(".check-text").text( $(this).parent().text());
		$(this).parent().css({"display":"none"})
	})
});*/
/**/
$(document).ready(function() {
	try {
		if ( typeof $(":file") != "undefined") {
			var tpl = '<div class="input-file-base">';
				tpl +='  <div class="input-file"><div><div><div class="field"></div></div></div></div>';
				tpl +='  <a href="javascript:void(0)">Обзор</a>';
				tpl +='</div>';
			$(":file").each(function(i){
				$(this).after(tpl);
				$(this).change(function(){
					value = $(this)[0].value/*.match(/\\([a-zA-Z0-9_\-]*\.[a-zA-Z0-9_\-]{1,8}$)/ig)*/;
					var charLangth = 20;
					$(this).next().find(".field").text(((value.length>charLangth)?'...'+value.substring(value.length-charLangth,value.length):value));
				})
			})
			$(":file").addClass('input-hidden');
		}
	} catch( err ) {
	}
});
/**/
$(document).ready(function() {
	if ($("a.ur-lico")[0] != undefined ) {
		$("a.ur-lico").bind('click',function(){
			//$(this).unbind('click');
			//$(this).css({"text-decoration":"none","cursor":"default"})
			$("div.ur-lico").slideToggle("medium", function() {
				$("a.ur-lico").html(this.style.display == "block" ? "Убрать реквизиты юридического лица" : "Прикрепить реквизиты юридического лица");
			});
		});
	}
});

/**/

$(document).ready(function() {
	toggleListInit();
});
function toggleListInit() {
	if ($('.toggle-list>dt')[0] != undefined ) {
		$(".toggle-list>dt").each(function(i){
			$(this).next().css({"display":"none"});
			$(this).css({"cursor":"pointer"});
			$(this).addClass('close');
			$(this).click(function() {
				if ($(this).next().css("display") == "none")
					$(this).removeClass('close');
				$(this).next().slideToggle("fast", function(){
					if ($(this).css("display")=="none")
						$(this).prev().addClass('close');
				});
			})
		})
	}
}
function reCreateSelect(id) {
	$("#"+id).css({"display":'block'});
	$("#"+id).next().remove();
	$("#open_"+id).remove();
	initSelect();
}
var last_height = 0;
var recalc = 0;
function basketSetHeight(goobCount) {
	recalc = $(".basket-goods img").length;
	$(".basket-goods img").load(function(){
		recalc--;
		if (recalc == 0)
			basketSetHeightSuccess(goobCount);
	})
	if (goobCount < 4)
		$(".basket-goods .goods").css({"overflow-y":"hidden"});
	$(".basket-goods .goods").height(last_height);
}
function basketSetHeightSuccess(goobCount) {
	if (goobCount < 4)
		$(".basket-goods .goods").css({"overflow-y":"hidden"});
	if (last_height)
		$(".basket-goods .goods").height(last_height);
	//setTimeout(function() {
	var height = 0;
	for (i = 0; i<goobCount; i++) {
		height+=$(".basket-goods tr:eq("+i+")").height();
	}
	last_height = height;
	$(".basket-goods .goods").animate({"height":height+"px"},250,function(){
		if (goobCount < 4)
			$(".basket-goods .goods").css({"overflow-y":"auto"});
	});
}

function initPlateSwitch() {
	if ($('.plate')[0] != undefined ) {
		$('.plate').each( function(i) {
			if( $(this).find('.plate-switch').length == 1) {
				$(this).find('.plate-content').css('display', 'none');
				$(this).addClass('no-decor');
				var $thisPlate = $(this);
				$(this).find('.plate-switch').click( function(event) {
					if ( $($('.plate')[i]).find('.plate-content').css('display') == 'none' ) {
						$($('.plate')[i]).find('.plate-content').css('display', 'block');
						$thisPlate.removeClass('no-decor');
					} else {
						$($('.plate')[i]).find('.plate-content').css('display', 'none');
						$thisPlate.addClass('no-decor');
					}
					$($('.plate')[i]).find('.plate-switch').css
					event.preventDefault();
				});
			}
		});
	}
}

var menuTimer = setTimeout( function() {}, 0);
$().ready(
	function() {
		var intervalIevel = new Array();
		if ($('.mcontaner>div')[0] != undefined ) {
			$('.mcontaner>div').hover(
				function() {
					clearTimeout(intervalIevel[0]);
					clearTimeout(intervalIevel[1]);
					clearTimeout(intervalIevel[2]);
					if ( !$(this).hasClass('hover') ) {
						$('.mcontaner *').removeClass('hover');
						$(this).addClass('hover');
					}
				},
				function() {
					var menuItem = $(this);
					if ( menuItem.hasClass('hover') ) {
						intervalIevel[0] = setTimeout( function() {
							menuItem.removeClass('hover');
							$('.mcontaner *').removeClass('hover');
						}, 400);
					}
				}
			);
		}
		if ($('.mcontaner .next-level-0')[0] != undefined ) {
			$('.mcontaner .next-level-0').hover(
				function() {
					clearTimeout(intervalIevel[1]);
					clearTimeout(intervalIevel[2]);
					if ( !$(this).find("div").first().hasClass('hover') ) {
						$('.mcontaner .next-level-0 *').removeClass('hover');
						$(this).find("div").first().addClass('hover');
					}
				},
				function() {
					var menuItem = $(this).find("div").first();
					if ( menuItem.hasClass('hover') ) {
						intervalIevel[1] = setTimeout( function() {
							$('.mcontaner .next-level-0 *').removeClass('hover');
							menuItem.removeClass('hover');
						}, 410);
					}
				}
			);
		}
		if ($('.mcontaner .next-level-1')[0] != undefined ) {
			$('.mcontaner .next-level-1').hover(
				function() {
					clearTimeout(intervalIevel[2]);
					if ( !$(this).find("div").first().hasClass('hover') ) {
						$('.mcontaner .next-level-1 *').removeClass('hover');
						$(this).find("div").first().addClass('hover');
					}
				},
				function() {
					var menuItem = $(this).find("div").first();
					if ( menuItem.hasClass('hover') ) {
						intervalIevel[2] = setTimeout( function() {
							$('.mcontaner .next-level-1 *').removeClass('hover');
							menuItem.removeClass('hover');
						}, 420);
					}
				}
			);
		}
	}
)
	
$(document).ready(function() {
	if ($("div.pickup .list .price .articul")[0] != undefined ) {
		$("div.pickup .list .price .articul").each(function(i){
			$(this).css({
				"padding-bottom":Math.round($(this).parent().height()/2-21)+"px"
			});
			//alert(Math.round($(this).parent().height()/2-20)+"px");
		})
	}
});

/* NEW 14.01 {*/
$(document).ready(function() {
	if ($(".order-only") != undefined) {
		var window = "<div class=\"order-window\">" + $("#orderonlytxt").html() + "</div>";
		$(".order-only").before($(window));
		$(".order-only a").bind("mouseover",function(){
			$(this).parent().prev().fadeIn("fast");
		})
		$(".order-only a").bind("mouseout",function(){
			$(this).parent().prev().fadeOut("fast");
		})
		$(".order-only a").attr("rev",$(".order-only a").attr("href"));
		$(".order-only a").attr("href","javascript:void(0)");
		$(".order-only a").click(function(){
			return showOrderItemConfirm($(this).attr("rev").replace(/#/,''));
		})
		orderOnlyResize();
	}
});

$(window).resize(function() {
	if ($(".order-only") != undefined) {
		orderOnlyResize();
	}
})

function orderOnlyResize() {
	var width = $(this).width();
	if (width<1300 && width>1000) {
		$(".order-window").css({
			"left":140-(1300-width)/2+"px"
		})
	} else
	if (width<1000) {
		$(".order-window").css({
			"left":"10px"
		})
	} else {
		$(".order-window").css({
			"left":"140px"
		})
	}
}
/* NEW 14.01 }*/

var initHelps = function() {
	if ( $('.acc-help').length > 1 && $('.acc-helper').length < 1 ) {
		$('body').append('<div class="acc-helper"><p>Необходимо нажать, чтобы добавить товар в корзину.</p></div>')
	}
	if ( $('.acc-help').length > 1 && $('.acc-helper').length == 1 ) {
		$('.acc-help').mouseover(function(event){
			/*$('.acc-helper').css({
				left: event.pageX - 70 + "px",
				top: event.pageY - 70 + "px"
			});*/
			$('.acc-helper').css({
				left: $(this).offset().left + 20 + "px",
				top: $(this).offset().top - 65 + "px"
			});
		}).mousemove(function(event){
			$('.acc-helper').css({
				left: $(this).offset().left + 20 + "px",
				top: $(this).offset().top - 65 + "px"
			});
		}).mouseout(function(){
			$('.acc-helper').css({
				left: "-1000px",
				top: "-1000px"
			});
		});
	}
}

var initExpHelp = function() {
	if ( $('.expected').length > 0 && $('.exp-helper').length < 1 ) {
		$('body').append('<div class="exp-helper"><p>Товар отсутствует на складе и ожидается к поступлению.<br/>Заказ на него можно оформить прямо сейчас.</p></div>')
	}
	if ( $('.exp-helper').length == 1 ) {
		$('.expected img').mouseover(function(event){
			$('.exp-helper').css({
				left: $(this).offset().left - 70 + "px",
				top: $(this).offset().top - 85 + "px"
			});
		}).mousemove(function(event){
			$('.exp-helper').css({
				left: $(this).offset().left - 70 + "px",
				top: $(this).offset().top - 85 + "px"
			});
		}).mouseout(function(){
			$('.exp-helper').css({
				left: "-1000px",
				top: "-1000px"
			});
		});
	}
}

$().ready( function() {
	initExpHelp();
	//if ( window.location.href.indexOf('debug=true') > 1 ) {
	var tooltipTimer = setInterval( function() {
	}, 1);
	var tooltipOver = false;
	var ttContent = {
		'logged': 'Если вы являетесь юридическим лицом и будете производить оплату на наш расчетный счет, Вам необходимо указать свои реквизиты. Нажмите на ссылку и заполните Ваши реквизиты',
		'notlogged': 'Если вы являетесь юридическим лицом и будете производить оплату на наш расчетный счет, Вам необходимо указать свои реквизиты. Заполнение реквизитов юридического лица доступно только для зарегистрированных покупателей, выполнивших вход в магазин с использованием своего логина и пароля.',
		'method': 'нашего магазина<br/>Нажмите, чтобы добавть товар<br/>Нажмите, чтобы добавть товар<br/>в корзину.'
	}

	//$('.ur-lico').each( function(i) {
	$('.tool-tip').each( function(i) {
		if ( $(this).attr('id').length < 1 ) {
			$(this).attr('id', 'notlogged');
		}
		$('body').append('<div class="tooltip" id="tooltip' + i + '"></div>');
		$('#tooltip' + i).html('<div class="tooltip-top"><div><div></div></div></div><div class="tooltip-content"><div><div></div></div></div><div class="tooltip-bottom"><div><div></div></div></div><div class="tooltip-y"></div>');
		$('.tooltip-content div:last').html(ttContent[$(this).attr('id')]);
		$(this).mouseover( function(event) {
			clearInterval (tooltipTimer);
			$('#tooltip' + i).css({
				left: event.pageX - 150 + 'px',
				top: event.pageY - 25 - parseInt( $('#tooltip' + i).height() ) + 'px'
			});
		});
		$(this).mousemove( function(event) {
			clearInterval (tooltipTimer);
			$('#tooltip' + i).css({
				left: event.pageX - 150 + 'px',
				top: event.pageY - 25 - parseInt( $('#tooltip' + i).height() ) + 'px'
			});
		});
		$('#tooltip' + i).mouseover( function() {
			tooltopOver = true;
			clearInterval (tooltipTimer);
		});
		$('#tooltip' + i).mousemove( function() {
			tooltopOver = true;
			clearInterval (tooltipTimer);
		});
		$('#tooltip' + i).mouseout( function() {
			tooltopOver = false;
			clearInterval (tooltipTimer);
			tooltipTimer = setInterval( function() {
				if (!tooltipOver) {
					$('#tooltip' + i).css({
						left: '-10000px',
						top: '-10000px'
					});
					tooltipOver = false;
				}
			}, 1000);
		});
		$(this).mouseout( function() {
			clearInterval (tooltipTimer);
			$('#tooltip' + i).css({
				left: '-10000px',
				top: '-10000px'
			});
		});
		$(this).click( function() {
			clearInterval (tooltipTimer);
			tooltipTimer = setInterval( function() {
				if (!tooltipOver) {
					$('#tooltip' + i).css({
						left: '-10000px',
						top: '-10000px'
					});
					tooltipOver = false;
				}
			}, 1000);
		});
	});
	//}
});

var cardToolTip = function() {
	var current;
	$('.paytype').each( function() {
		if  ( $(this).parents('.subforms:first').css('display') == 'block' ) {
			current = $(this).find('option:selected').val();
		}
	});

	$('.card-tool-tip').each( function(i) {
		var cardToolTipX = $($('.card-tool-tip')[i]).offset().left;
		var cardToolTipY = $($('.card-tool-tip')[i]).offset().top;
		switch(current) {
			case 'cardonline':
			case 'cardoffline':
				$('#cardtooltip' + i).css({
					left: cardToolTipX + 20 + 'px',
					top: cardToolTipY - 40 + 'px'
				});
				break;
			case 'comepay':
				$('#cardtooltip' + i).css({
					left: cardToolTipX + 20 + 'px',
					top: cardToolTipY - 40 + 'px'
				});
				break;
			case "sbrf":
				$('#cardtooltip' + i).css({
					left: cardToolTipX + 20 + "px",
					top: cardToolTipY - 40 + "px"
				});
				break;
			case "credit_rs":
				$('#cardtooltip' + i).css({
					left: cardToolTipX + 20 + "px",
					top: cardToolTipY - 40 + "px"
				});
				break;
			default:
				$('#cardtooltip' + i).css({
					left: '-10000px',
					top: '-10000px'
				});
		}
		$(window).resize( function() {
			if ( parseInt($('#cardtooltip' + i).css('left')) > 0 && parseInt($('#cardtooltip' + i).css('top')) > 0 ) {
				cardToolTipX = $($('.card-tool-tip')[i]).offset().left;
				cardToolTipY = $($('.card-tool-tip')[i]).offset().top;
				if ( cardToolTipX > 0 && cardToolTipY > 0 ) {
					$('#cardtooltip' + i).css({
						left: cardToolTipX + 20 + 'px',
						top: cardToolTipY - 40 + 'px'
					});
				}
			}
		});
	});
}

var ctooltipTimer = setInterval( function() {
}, 1);
var ctooltipOver = false;
$().ready( function() {
/*
	var cttContent = {
		'green': 'Товар "новинка". Нажмите, чтобы добавить товар в корзину.',
		'red': 'На данный товар назначена "специальная цена". Нажмите, чтобы> добавить товар в корзину.'
	}
*/

	//$('.ur-lico').each( function(i) {
	initHelpers();
	if ( $('#plateswitch').length ) {
		$('#plateon').click( function( event ) {
			event.preventDefault();
			$(this).parents('.plate:first').find('.plate-content:first').removeAttr('style');
			$(this).css({display: 'none'});
			$('#plateoff').removeAttr('style');
			$('#plateoff').parents('.plate:first').removeClass('no-decor');
		});
		$('#plateoff').click( function( event ) {
			event.preventDefault();
			$(this).parents('.plate:first').find('.plate-content:first').css({
				position: 'absolute',
				top: -11111,
				left: -11111
			});
			$(this).css({display: 'none'});
			$('#plateon').removeAttr('style');
			$('#plateon').parents('.plate:first').addClass('no-decor');
		});
		if ( $('#plateon').css('display') != 'none' ) {
			$('#plateon').parents('.plate:first').addClass('no-decor');
		} else if ( $('#plateoff').css('display') != 'none' ) {
			$('#plateoff').parents('.plate:first').removeClass('no-decor');
		}
	}
});

var initHelpers = function() {
	$('.ctooltip').remove();
	$('.cardtooltip').remove();
	
	if ($("#theme").length > 0) {
		cttContent["hlpdelivery"] = deliveryInfo[$("#theme").val()];
		cttContent["card"] = paymentInfo[$("#f" + $("#theme").val() + "_paytype").val()];
	}
	
	$('.cost').each( function(i) {
		if ( $(this).attr('id').length > 0 ) {
			$('body').append('<div class="ctooltip" id="ctooltip' + i + '"></div>');
			$('#ctooltip' + i).html('<p>' + cttContent[$(this).attr('id').replace(/_.*/,'')] + '</p>');
			$(this).mouseover( function(event) {
				clearInterval (ctooltipTimer);
				$('#ctooltip' + i).css({
					left: event.pageX - 70 + 'px',
					top: event.pageY - 5 - parseInt( $('#ctooltip' + i).height() ) + 'px'
				});
			});
			$(this).mousemove( function(event) {
				clearInterval (ctooltipTimer);
				$('#ctooltip' + i).css({
					left: event.pageX - 70 + 'px',
					top: event.pageY - 5 - parseInt( $('#ctooltip' + i).height() ) + 'px'
				});
			});
			$('#ctooltip' + i).mouseover( function() {
				ctooltopOver = true;
				clearInterval (ctooltipTimer);
			});
			$('#ctooltip' + i).mousemove( function() {
				ctooltopOver = true;
				clearInterval (ctooltipTimer);
			});
			$('#ctooltip' + i).mouseout( function() {
				ctooltopOver = false;
				clearInterval (ctooltipTimer);
				ctooltipTimer = setInterval( function() {
					if (!ctooltipOver) {
						$('#ctooltip' + i).css({
							left: '-10000px',
							top: '-10000px'
						});
						ctooltipOver = false;
					}
				}, 1000);
			});
			$(this).mouseout( function() {
				clearInterval (ctooltipTimer);
				$('#ctooltip' + i).css({
					left: '-10000px',
					top: '-10000px'
				});
			});
			$(this).click( function() {
				clearInterval (ctooltipTimer);
				ctooltipTimer = setInterval( function() {
					if (!ctooltipOver) {
						$('#ctooltip' + i).css({
							left: '-10000px',
							top: '-10000px'
						});
						ctooltipOver = false;
					}
				}, 1000);
			});
		}
	});
	$('.helper-tool-tip').each( function(i) {
		if ( $(this).attr('id').length > 0 ) {
			$('body').append('<div class="tooltip" id="c-tooltip' + i + '"></div>');
		$('#c-tooltip' + i).html('<div class="tooltip-top"><div><div></div></div></div><div class="tooltip-content"><div><div></div></div></div><div class="tooltip-bottom"><div><div></div></div></div><div class="tooltip-y"></div>');
			$('#c-tooltip' + i + ' .tooltip-content div:last').html(cttContent[$(this).attr('id').replace(/_.*/,'')]);
			$(this).mouseover( function(event) {
				clearInterval (ctooltipTimer);
				$('.tooltip').css({
					left: '-10000px',
					top: '-10000px'
				})
				$('#c-tooltip' + i).css({
					left: event.pageX - 150 + 'px',
					top: event.pageY - 25 - parseInt( $('#c-tooltip' + i).height() ) + 'px'
				});
			});
			$(this).mousemove( function(event) {
				clearInterval (ctooltipTimer);
				$('#c-tooltip' + i).css({
					left: event.pageX - 150 + 'px',
					top: event.pageY - 25 - parseInt( $('#c-tooltip' + i).height() ) + 'px'
				});
			});
			$('#c-tooltip' + i).mouseover( function() {
				ctooltopOver = true;
				clearInterval (ctooltipTimer);
			});
			$('#c-tooltip' + i).mousemove( function() {
				ctooltopOver = true;
				clearInterval (ctooltipTimer);
			});
			$('#c-tooltip' + i).mouseout( function() {
				ctooltopOver = false;
				clearInterval (ctooltipTimer);
				ctooltipTimer = setInterval( function() {
					if (!ctooltipOver) {
						$('#c-tooltip' + i).css({
							left: '-10000px',
							top: '-10000px'
						});
						ctooltipOver = false;
					}
				}, 1000);
			});
			/*$(this).mouseout( function() {
				clearInterval (ctooltipTimer);
				$('#c-tooltip' + i).css({
					left: '-10000px',
					top: '-10000px'
				});
			});*/
			$(this).mouseout( function() {
				clearInterval (ctooltipTimer);
				ctooltipTimer = setInterval( function() {
					if (!ctooltipOver) {
						$('#c-tooltip' + i).css({
							left: '-10000px',
							top: '-10000px'
						});
						ctooltipOver = false;
					}
				}, 1000);
			});
			$(this).click( function() {
				clearInterval (ctooltipTimer);
				ctooltipTimer = setInterval( function() {
					if (!ctooltipOver) {
						$('#c-tooltip' + i).css({
							left: '-10000px',
							top: '-10000px'
						});
						ctooltipOver = false;
					}
				}, 1000);
			});
		}
	});
	$('.card-tool-tip').each( function(i) {
		if ( $(this).attr('id').length > 0 && $(this).parents('.subforms:first').css('display') != 'none' ) {
			$('body').append('<div class="cardtooltip" id="cardtooltip' + i + '"></div>');
			$('.paytype').each( function() {
				if  ( $(this).parents('.subforms:first').css('display') == 'block' ) {
					if ( $('.cardtooltip').length ) {
						$('.cardtooltip:first').html('<img src="/project/imgs/cards/' + $(this).find('option:selected').val() + '.jpg" alt="" />');
					}
				}
			});
			cardToolTip();
		}
	});
}
