var movestate = 0;
var startmousex = 0;
var startmousey = 0;
var bigbannerpos = 0;
var counter = 0;
var subcat_list_type = 1;

function large_image(products_id) {//},image,ww,hh) {

	$('#image_box2').load('/imageGallery-' + products_id, function() {
		$('#image_box_gallery').serialScroll({
			items : 'li',
			target : '#galerie2_pictures',
			prev : '#moveleft2',
			next : '#moveright2',
			offset : 0, //when scrolling to photo, stop 230 before reaching it (from the left)
			start : 0, //as we are centering it, start at the 2nd
			duration : 1200,
			step : 5,
			force : true,
			stop : true,
			lock : false,
			cycle : false, //don't pull back once you reach the end
			easing : 'easeOutQuart', //use this easing equation for a funny effect
			jump : false //click on the images to scroll to them
		});
		document.getElementById('image_box2').style.display = "block";
	});
}

function big_image(image) {
	var strImage=image;
	image=image.replace("small","large"); 
 
	
	imgTag=document.getElementById('image_box2_image');
	imgTag.src = image;
	
	$("#image_box2_image").load(function (){
		ww=document.getElementById('image_box2_image').naturalWidth;
		hh=document.getElementById('image_box2_image').naturalHeight;
		 
		a = imageSizes(ww, hh, 950, 500);
		if(ww > 950 || hh > 500) {
			ww = a[0];
			hh = a[1];
		}
		if (ww>0 && hh>0) {
		document.getElementById('image_box2_image').style.width = ww + 'px';
		document.getElementById('image_box2_image').style.height = hh + 'px';
 	}
	//document.getElementById('bigimage').style.top = Math.round((500 - hh) / 2) + 'px';

		
	});
	
	
	if(document.getElementById('bigimage').style.display != "block") {
		centerDiv(950, 600, 'bigimage');
		document.getElementById('bigimage').style.left = '5px';
		document.getElementById('bigimage').style.display = "block";
	}
	
}
function hidebigimage() {
	document.getElementById('bigimage').style.display = "none";
}
function show_large_image(image, ww, hh) {
	document.getElementById('image_box2_image').src = image;
	a = imageSizes(ww, hh, 950, 500);
	if(ww > 950 || hh > 500) {
		ww = a[0];
		hh = a[1];
	}

	document.getElementById('image_box2_image').style.width = ww + 'px';
	document.getElementById('image_box2_image').style.height = hh + 'px';
	//	document.getElementById('image_box2_image').style.left=Math.round((950-ww)/2)+'px';
	document.getElementById('image_box2_image').style.top = Math.round((500 - hh) / 2) + 'px';

	if(document.getElementById('image_box2').style.display != "block") {
		centerDiv(950, 600, 'image_box2');
		document.getElementById('image_box2').style.left = '5px';
		document.getElementById('image_box2').style.display = "block";
	}
}

function hidebiggerpict(forceclose) {
	//	document.getElementById('image_box2').innerHTML="";
	$('image_box2').empty();
	document.getElementById('image_box2').style.display = "none";
}

function centerDiv(Xwidth, Yheight, divid) {
	// First, determine how much the visitor has scrolled

	var scrolledX, scrolledY;
	if(self.pageYOffset) {
		scrolledX = self.pageXOffset;
		scrolledY = self.pageYOffset;
	} else if(document.documentElement && document.documentElement.scrollTop) {
		scrolledX = document.documentElement.scrollLeft;
		scrolledY = document.documentElement.scrollTop;
	} else if(document.body) {
		scrolledX = document.body.scrollLeft;
		scrolledY = document.body.scrollTop;
	}

	// Next, determine the coordinates of the center of browser's window

	var centerX, centerY;
	if(self.innerHeight) {
		centerX = self.innerWidth;
		centerY = self.innerHeight;
	} else if(document.documentElement && document.documentElement.clientHeight) {
		centerX = document.documentElement.clientWidth;
		centerY = document.documentElement.clientHeight;
	} else if(document.body) {
		centerX = document.body.clientWidth;
		centerY = document.body.clientHeight;
	}

	// Xwidth is the width of the div, Yheight is the height of the
	// div passed as arguments to the function:
	var leftOffset = scrolledX + (centerX - Xwidth) / 2;
	var topOffset = scrolledY + (centerY - Yheight) / 2;
	// The initial width and height of the div can be set in the
	// style sheet with display:none; divid is passed as an argument to // the function
	var o = document.getElementById(divid);
	var r = o.style;
	r.position = 'absolute';
	r.top = topOffset - 100 + 'px';
	r.left = leftOffset + 'px';
	r.display = "block";
}

function imageSizes(width, height, maxwidth, maxheight) {
	newW = 0;
	newH = 0;
	if(width != 0 && height != 0) {
		if(width >= height) {
			pomer = maxwidth / width;
			newW = pomer * width;
			newH = pomer * height;
		}

		if(width < height) {
			pomer = maxheight / height;
			newH = pomer * height;
			newW = pomer * width;
		}

		if(newW > maxwidth) {
			pomer = maxwidth / newW;
			newW = pomer * newW;
			newH = pomer * newH;
		}

		if(newH > maxheight) {
			pomer = maxheight / newH;
			newW = pomer * newW;
			newH = pomer * newH;
		}

	} else {
		if(newW == 0 || newH == 0) {
			newW = maxwidth;
			newH = maxheight;
		}
	}
	var a = new Array(Math.round(newW), Math.round(newH));
	return a;

}

function isDefined(variable) {
	return (!(!(document.getElementById(variable))))
}

function textclear(co) {
	if(co.value == "Hledej...") {
		co.value = "";
	}
}

function getXYpos(elem) {
	if(!elem) {
		return {
			"x" : 0,
			"y" : 0
		};
	}
	var xy = {
		"x" : elem.offsetLeft,
		"y" : elem.offsetTop
	}
	var par = getXYpos(elem.offsetParent);
	for(var key in par) {
		xy[key] += par[key];
	}
	return xy;
}

function stock_mouseover(id, tid) {

	if($('#' + tid + id).html().length == 0) {
		$('#' + tid + id).load('/stavskladu-' + id);
	}

	$('#' + tid + id).show();
	$('#' + tid + id).parent().css('z-index', 101);

}

function stock_mouseout(id, tid) {
	$('#' + tid + id).hide();
	$('#' + tid + id).parent().css('z-index', 100);
}

document.onmousemove = mouseMove;
document.onmouseup = mouseUp;

var dragObject = null;
var mouseOffset = null;
var mouseX = "0px";
var mouseY = "0px";

function getMouseOffset(target, ev) {
	ev = ev || window.event;

	var docPos = getPosition(target);
	var mousePos = mouseCoords(ev);
	return {
		x : mousePos.x - docPos.x,
		y : mousePos.y - docPos.y
	};
}

function getPosition(e) {
	var left = 0;
	var top = 0;

	while(isDefined('e.offsetParent') == true) {
		left += e.offsetLeft;
		top += e.offsetTop;
		e = e.offsetParent;
	}
	left += e.offsetLeft;
	top += e.offsetTop;

	return {
		x : left,
		y : top
	};
}

function mouseMove(ev) {
	ev = ev || window.event;
	var mousePos = mouseCoords(ev);

	if(dragObject) {
		dragObject.style.position = 'absolute';
		dragObject.style.top = mousePos.y - mouseOffset.y + "px";
		dragObject.style.left = mousePos.x - mouseOffset.x + "px";

		return false;
	}
}

function mouseUp() {
	dragObject = null;
}

function mouseCoords(ev) {
	var x = 0;
	var y = 0;

	if(ev.pageX || ev.pageY) {
		return {
			x : ev.pageX,
			y : ev.pageY
		};
	}
	x = ev.clientX;
	if(isDefined('document.body.scrollLeft')) {
		x = x + document.body.scrollLeft;
	}
	if(isDefined('document.body.clientLeft')) {
		x = x + document.body.clientLeft;
	}
	y = ev.clientY;
	if(isDefined('document.body.scrollTop')) {
		y = y + document.body.scrollTop;
	}
	if(isDefined('document.body.clientTop')) {
		y = y + document.body.clientTop;
	}
	return {
		x : x,
		y : y
	};
}

function makeDraggable(item) {
	if(!item)
		return;
	item.onmousedown = function(ev) {
		dragObject = this;
		mouseOffset = getMouseOffset(this, ev);
		return false;
	}
}

function bigimageonload() {
	document.getElementById('image_box2_image').style.display = 'block';
	//				document.getElementById('nahravam').style.display='none';
}

function stats(productsid) {
	ww = 1050;
	hh = 850;
	im = "/productsview-" + productsid + ".png"
	posy = document.documentElement.scrollTop;
	document.getElementById('nahravam').style.display = 'block';
	document.getElementById('image_box2').style.width = ww + 'px';
	document.getElementById('image_box2').style.height = hh + 'px';
	document.getElementById('image_box2_image').style.display = 'none';
	document.getElementById('image_box2_image').src = im;
	document.getElementById('image_box2_image').style.width = ww + 'px';
	document.getElementById('image_box2_image').style.height = hh + 'px';
	document.getElementById('image_box2').style.left = (Math.floor((document.body.offsetWidth - ww) / 2)) + "px";
	document.getElementById('image_box2').style.top = posy + 100 + "px";
	document.getElementById('image_box2_kriz').style.left = (Math.floor(ww / 2) - 30) + 'px';
	document.getElementById('image_box2_kriz').style.top = '-' + (hh - 10) + "px";
	document.getElementById('image_box2').style.display = "block";

}

function colselShow() {
	document.getElementById("colsel").style.display = 'block';
}

function colselHide() {
	document.getElementById("colsel").style.display = 'none';
}

function setcolumns(num) {
	document.getElementById('colnum').value = num;
	document.getElementById('colnumform').submit();
}

function getresolution() {
	var today = new Date();
	var the_date = new Date("December 31, 2023");
	var the_cookie_date = the_date.toGMTString();
	var the_cookie = "UserResolution=" + screen.width + "x" + screen.height;
	var the_cookie = the_cookie + ";expires=" + the_cookie_date;
	document.cookie = the_cookie;

}

function loginbox(co) {
	if(co == 1) {
		document.getElementById("loginbox").style.display = "block";
	} else {
		document.getElementById("loginbox").style.display = "none";
	}
}

function odesli(co, akce) {
	document.getElementById(co).action = akce;
	document.getElementById(co).submit();
}

function send_xmlhttprequest(state_change, method, url, content, headers) {
	var xmlhttp = (window.XMLHttpRequest ? new XMLHttpRequest() : (window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : false));
	if(!xmlhttp) {
		return false;
	}
	xmlhttp.open(method, url);
	xmlhttp.onreadystatechange = function() {
		state_change(xmlhttp);
	};
	headers = headers || {};
	headers['X-Requested-With'] = headers['X-Requested-With'] || 'XMLHttpRequest';
	for(var key in headers) {
		xmlhttp.setRequestHeader(key, headers[key]);
	}
	xmlhttp.send(content);

	return true;
}

function post_xmlhttprequest(state_change, url, form, headers) {
	var elements = form.elements;
	var content = [];
	for(var i = 0; i < elements.length; i++) {
		if(elements[i].attributes.name && elements[i].attributes.name.specified && !elements[i].disabled) {
			if(/^(select)$/i.test(elements[i].tagName)) {
				var options = elements[i].options;
				for(var j = 0; j < options.length; j++) {
					if(options[j].selected) {
						var value = (options[j].attributes.value && options[j].attributes.value.specified ? options[j].value : options[j].text);
						content.push(encodeURIComponent(elements[i].name) + '=' + encodeURIComponent(value));
					}
				}
			} else if(!/^(submit|reset|button|file|image)$/i.test(elements[i].type) && (!/^(radio|checkbox)$/i.test(elements[i].type) || elements[i].checked)) {
				content.push(encodeURIComponent(elements[i].name) + '=' + encodeURIComponent(elements[i].value));
			}
		}
	}
	if(!headers) {
		headers = {};
	}
	headers['Content-Type'] = 'application/x-www-form-urlencoded';
	return send_xmlhttprequest(state_change, 'POST', url, content.join('&'), headers);
}

function addToCart(form, ProductsID) {

	return post_xmlhttprequest(function(xmlhttp) {
		if(xmlhttp.readyState == 4) {

			dokosiku();
			$("#kosik").load("/stavkosiku");
			$(".cart_suggestions").load("/cartConfirmation-" + ProductsID);

			$("#cart_confirmation").show();
			$.scrollTo($('#cart_confirmation'), 800);
		}
	}, '/dokosiku', form);
}

function buystockproduct(stock_products_id, ProductsID) {
	var form = document.getElementById('form1');
	$('#stock_products_id').attr('value', stock_products_id);
	$("#typ_akce").val("add_stock_product");

	//	document.getElementById('form1').submit();
	return post_xmlhttprequest(function(xmlhttp) {
		if(xmlhttp.readyState == 4) {
			dokosiku();
			//        	$("#kosik").load("/stavkosiku");
			//        	$(".cart_suggestions").load("/cartConfirmation-"+ProductsID);

			//        	$("#cart_confirmation").text(xmlhttp.responseText);
			//         	$("#cart_confirmation").show();
			//          $.scrollTo($('#cart_confirmation'),800);
		}
	}, '/dokosiku', form);
}

//$('.obrazek').click(function(e)  {
//	  window.alert("click");
//   if(e.target.className != "sysmessage" && e.target.className != "callmediv" && e.target.className != "mailmediv" && e.target.className != "AtypickyRozmerBox" )
//   {
//       $(".sysmessage").hide();
//       $(".callmediv").hide();
//       $(".mailmediv").hide();
//       $(".AtypickyRozmerBox").hide();
//   }
//  }
//);

$(document).bind('click', function(e) {

	var $clicked = $(e.target);
	// get the element clicked
	if(!($clicked.is('.fastbox') || $clicked.parents().is('.fastbox') )) {
		if(!($clicked.is('#callmediv') || $clicked.parents().is('#callmediv'))) {
			$('#callmediv').hide();
		}
		if(!($clicked.is('#mailmediv') || $clicked.parents().is('#mailmediv'))) {
			$('#mailmediv').hide();
		}
	}

	if(!($clicked.is('#sysmessage') || $clicked.parents().is('#sysmessage'))) {
		$('#sysmessage').hide();
	}
});

jQuery.easing.easeOutQuart = function(x, t, b, c, d) {
	return -c * (( t = t / d - 1) * t * t * t - 1) + b;
};
acttab = 1;
zakladnicena = 0;
imgselected = Array("/templates/main/images/detail_left_popis_selected.gif", "/templates/main/images/detail_left_dalsifoto_selected.gif", "/templates/main/images/detail_left_skladovezasoby_selected.gif", "/templates/main/images/detail_left_diskuze_selected.gif");
imggray = Array("/templates/main/images/detail_left_popis_gray.gif", "/templates/main/images/detail_left_dalsifoto_gray.gif", "/templates/main/images/detail_left_skladovezasoby_gray.gif", "/templates/main/images/detail_left_diskuze_gray.gif");
imgnormal = Array("/templates/main/images/detail_left_popis.gif", "/templates/main/images/detail_left_dalsifoto.gif", "/templates/main/images/detail_left_skladovezasoby.gif", "/templates/main/images/detail_left_diskuze.gif");

function tab_hover(number) {
	if(acttab != number) {
		sel = document.getElementById("tabimage" + number);
		sel.src = imgnormal[number - 1];
	}

	if(number == 3 && acttab != 3) {
		document.getElementById("stock_table").style.display = 'block';
	}
}

function tab_out(number) {
	if(acttab != number) {
		sel = document.getElementById("tabimage" + number);
		sel.src = imggray[number - 1];
	}
	document.getElementById("stock_table").style.display = 'none';

}

function add_quantity(quantity) {
	//	document.getElementById('cart_quantity').value=parseFloat(document.getElementById('cart_quantity').value)+quantity;
	//	if (document.getElementById('cart_quantity').value<=0) { document.getElementById('cart_quantity').value=1;}
	//	if (isNaN(document.getElementById('cart_quantity').value)) { document.getElementById('cart_quantity').value=1;}
	//	document.getElementById("cart_quantity2").value=document.getElementById("cart_quantity").value;
	countprice();
}

function kschange() {
	//	if (!isNaN(document.getElementById('cart_quantity2').value)) { document.getElementById('cart_quantity').value=document.getElementById('cart_quantity2').value;}
	countprice();
}

function kschange2() {
	if(!isNaN(document.getElementById('cart_quantity').value)) {
		document.getElementById('cart_quantity2').value = document.getElementById('cart_quantity').value;
	}
	countprice();
}

function tab_click(number) {
	sel = document.getElementById("tabimage" + acttab);
	sel.src = imggray[acttab - 1];
	sel = document.getElementById("tabimage" + number);
	sel.src = imgselected[number - 1];
	act = document.getElementById("tab" + acttab);
	act.style.display = "none";
	act = document.getElementById("tab" + number);
	act.style.display = "block";
	document.getElementById("stock_table").style.display = 'none';
	acttab = number;
}

function countprice() {
	form = document.getElementById('form1');
 
	//form=$('#form1');
	baseprice = parseFloat($("#baseprice").attr('value'));
	// $("#baseprice").attr('value');
	montaz=0;vynos1=0;vynos2=0;
	var str = "";

	//baseprice=baseprice.toFixed(curdec);
	for( x = 0; x < pole3.length; x++) {
		for( i = 0; i < form.elements.length; i++) {
		 
			if((form.elements[i].type == 'radio' || form.elements[i].type == 'checkbox')) {
				if(form.elements[i].checked == true) {
					if(form.elements[i].name.substr(9, form.elements[i].name.length - 11) == pole3[x]) {
						num = parseFloat(pole1[form.elements[i].value][0]);
						baseprice = baseprice + num;
						montaz=montaz+pole1[form.elements[i].value][6];
						vynos1=vynos1+pole1[form.elements[i].value][7];
						vynos2=vynos2+pole1[form.elements[i].value][8];
						
						if(pole1[form.elements[i].value][1] == 1) {
							if(pole1[form.elements[i].value][3] == 1) {
								if(str.length > 0) {
									str = str + ", ";
								}
								str = str + pole1[form.elements[i].value][2];
							}
						 
						}
					}
				}
			}
		}
	}

	for( x = 0; x < pole4.length; x++) {
		for( i = 0; i < form.elements.length; i++) {
			if((form.elements[i].attributes['type'].nodeValue == 'radio' || form.elements[i].attributes['type'].nodeValue == 'checkbox') && form.elements[i].checked == true) {
				if(form.elements[i].name.substr(9, form.elements[i].name.length - 11) == pole4[x][0] && (form.elements[i].value == pole4[x][1])) {
					$("#attr_cena_" + pole4[x][0] + "_" + pole4[x][1]).text('+ ' + pole4[x][2] + '% ~ ' + price_format(parseFloat(baseprice * pole4[x][2] / 100), curdec, ' ', '.', '', ' ' + currsign, '', ''));
					baseprice = parseFloat(((pole4[x][2] + 100) / 100) * baseprice);
				}
			}
		}
	}

	for( x = 0; x < pole4.length; x++) {
		$("#input" + pole4[x][1]).each(function(index) {
			if($(this).attr('name') == 'attribute' + pole4[x][0] + '[]') {

				if($(this).attr('checked') == false) {
					$("#attr_cena_" + pole4[x][0] + "_" + pole4[x][1]).text('+ ' + pole4[x][2] + '% ~ ' + price_format(parseFloat(baseprice * pole4[x][2] / 100), curdec, ' ', '.', '', ' ' + currsign, '', ''));
				}

			}
		});
	}
	//cena = price_format(baseprice) +' '+ currsign;
 
 	
	if ($("#montaz").attr("checked")=="checked") { baseprice=baseprice+Math.round((base_montaz+montaz)*dph_high); }
	if ($("#vynos1").attr("checked")=="checked") { baseprice=baseprice+Math.round((base_vynos1+vynos1)*dph_high);}
	if ($("#vynos2").attr("checked")=="checked") { baseprice=baseprice+Math.round((base_vynos2+vynos2)*dph_high);}
	cena = price_format(baseprice, curdec, ' ', '.', '', ' ' + currsign, '', '');
	$("#cena_vynos1 i").text('(+'+Math.round((base_vynos1+vynos1)*dph_high)+' Kč)');
	$("#cena_vynos2 i").text('(+'+Math.round((base_vynos2+vynos2)*dph_high)+' Kč)');
	$("#cena_montaz i").text('(+'+Math.round((base_montaz+montaz)*dph_high)+' Kč)');
	document.getElementById('products_price').innerText = cena;
	document.getElementById('products_price').textContent = cena;
	//document.getElementById('products_price2').innerText = cena;
	//document.getElementById('products_price2').textContent = cena;

	skladem = false;
	for( i = 0; i < pole2.length; i++) {
		if(pole2[i][0] == str && pole2[i][1] >= form.elements['cart_quantity'].value) {
			skladem = true;
		}
	}

	if(skladem == true) {
		document.getElementById('neniskladem').style.display = "none";
		document.getElementById('jeskladem').style.display = "block";
	} else {
		document.getElementById('neniskladem').style.display = "block";
		document.getElementById('jeskladem').style.display = "none";
	}
}

function price_format(num, dec, thou, pnt, curr1, curr2, n1, n2) {
	var x = Math.round(num * Math.pow(10, dec));
	if(x >= 0)
		n1 = n2 = '';
	var y = ('' + Math.abs(x)).split('');
	var z = y.length - dec;
	if(z < 0)
		z--;
	for(var i = z; i < 0; i++)
	y.unshift('0');
	if(z < 0)
		z = 1;
	if(dec > 0) {
		y.splice(z, 0, pnt);
		if(y[0] == pnt)
			y.unshift('0');
	}
	while(z > 3) {
		z -= 3;
		y.splice(z, 0, thou);
	}
	var r = curr1 + n1 + y.join('') + n2 + curr2;
	return r;
}

function selectAttr(option_id) {
	posy = document.documentElement.scrollTop;
	document.getElementById('detailAttributesImageSelect' + option_id).style.left = -400 + "px";
	//(Math.floor((document.body.offsetWidth)/2))+'px';
	document.getElementById('detailAttributesImageSelect' + option_id).style.display = "block";

}

function hideAttr(option_id) {
	document.getElementById('detailAttributesImageSelect' + option_id).style.display = "none";
}

function vyberImgInput(inp, img) {

	if(document.getElementById("imgvybrano" + img)) {
		document.getElementById("imgvybrano" + img).src = document.getElementById("attrimg" + inp).src;
		document.getElementById("vybrano" + img).innerHTML = document.getElementById("nazev" + inp).innerHTML;
		document.getElementById("imgvybrano" + img).width = document.getElementById("attrimg" + inp).width;
		document.getElementById("imgvybrano" + img).height = document.getElementById("attrimg" + inp).height;
	}

	if(!document.getElementById("input" + img + inp).checked) {
		document.getElementById("input" + img + inp).checked = true;
	}

	countprice();
}

function updateImgInput(inp, img) {

	if(document.getElementById("imgvybrano" + img)) {
		document.getElementById("imgvybrano" + img).src = document.getElementById("attrimg" + inp).src;
		document.getElementById("vybrano" + img).innerHTML = document.getElementById("nazev" + inp).innerHTML;
	}

	countprice();
} 

function zobrazdiskusi() {
	document.getElementById('tab4').style.display = "block";
}

function diskuse_addcomment() {
	posy = document.documentElement.scrollTop;

	document.getElementById('addcomment').style.top = posy + 100 + "px";
	document.getElementById('addcomment').style.left = (Math.floor((document.body.offsetWidth - 500) / 2)) + "px";
	document.getElementById('addcomment').style.display = 'block';
}

function diskuse_addcomment_close() {
	document.getElementById('addcomment').style.display = 'none';
}

function callme() {
	posy = document.documentElement.scrollTop;
	document.getElementById('callmediv').style.top = posy + 250 + "px";
	document.getElementById('callmediv').style.left = "300px";
	document.getElementById('callmediv').style.display = 'block';
	//	$('.callmediv').show();

}

function mailme() {
	posy = document.documentElement.scrollTop;
	document.getElementById('mailmediv').style.top = posy + 250 + "px";
	document.getElementById('mailmediv').style.left = "300px";
	document.getElementById('mailmediv').style.display = 'block';
}

function onlynumbers(evt) {
	var theEvent = evt || window.event;
	var key = theEvent.keyCode || theEvent.which;
	key = String.fromCharCode(key);
	var regex = /[0-9]/;
	if(!regex.test(key) && !(theEvent.keyCode == 8 || theEvent.keyCode == 46 || theEvent.keyCode == 37 || theEvent.keyCode == 39 || theEvent.keyCode == 50)) {
		theEvent.returnValue = false;
		// theEvent.preventDefault();
	}
}

function atypMatrace(co, ev) {
	ev = ev || window.event;
	var mousePos = mouseCoords(ev);

	if(co == 1) {

		document.getElementById("AtypickyRozmerBox").style.left = mousePos.x - 200;
		document.getElementById("AtypickyRozmerBox").style.top = mousePos.y;
		document.getElementById("AtypickyRozmerBox").style.display = "block";
	} else {
		document.getElementById("AtypickyRozmerBox").style.display = "none";
	}
}

function atypOdesli() {
	document.getElementById("AtypickyRozmerForm").action = "/atyp";
	document.getElementById("AtypickyRozmerForm").submit();
}

function showParametr(id) {

	$.scrollTo($('#parametr' + id), 800);
}

function large_image_detail(image, ww, hh) {
	document.getElementById('masterImage').src = image;
	a = imageSizes(ww, hh, 700, 400);
	if(ww > 700 || hh > 400) {
		ww = a[0];
		hh = a[1];
	}

	document.getElementById('masterImage').style.width = ww + 'px';
	document.getElementById('masterImage').style.height = hh + 'px';
	document.getElementById('masterImage').style.left = Math.round((950 - ww) / 2) + 'px';
	document.getElementById('masterImage').style.top = Math.round((500 - hh) / 2) + 'px';

}

jQuery(function($) {

	$('#image_gallery').serialScroll({
		items : 'li',
		target : '#galerie_pictures',
		prev : '#moveleft',
		next : '#moveright',
		offset : 0, //when scrolling to photo, stop 230 before reaching it (from the left)
		start : 0, //as we are centering it, start at the 2nd
		duration : 1200,
		step : 5,
		force : true,
		stop : true,
		lock : false,
		cycle : false, //don't pull back once you reach the end
		easing : 'easeOutQuart', //use this easing equation for a funny effect
		jump : false //click on the images to scroll to them
	});

	$('#bigbanner').serialScroll({
		items : 'li',
		target : '#bigbanner_images',
		offset : 0, //when scrolling to photo, stop 230 before reaching it (from the left)
		start : 0, //as we are centering it, start at the 2nd
		interval : 8000,
		duration : 1000,
		step : 1,
		force : true,
		stop : false,
		axis : 'y',
		lock : false,
		cycle : true, //don't pull back once you reach the end
		easing : 'easeOutQuart', //use this easing equation for a funny effect
		jump : false, //click on the images to scroll to them
		onBefore : function(e, elem, $pane, $items, pos) {
			$(".switcher li").css("background-color", '#f9f9f9');
			$(".switcher li").css("color", "black");
			$(".switcher li").each(function(index) {
				bigbannerpos = pos;
				if(($(this).text() - 1) == pos) {
					$(this).css("background-color", '#383838');
					$(this).css("color", 'white');
				}
			})
		}
	});

	$('.spodek .left .left_box .out').attr("href", 'http://www.rothwell.cz/matrace');

	$('.fastbox img').bind('mouseover', function() {
		me = $(this);
		if(me.attr('src') == '/templates/main/images/obalka.gif') {
			me.attr('src', "/templates/main/images/obalka-cervena.gif");
		}
		if(me.attr('src') == '/templates/main/images/sipka_zpet.gif') {
			me.attr('src', "/templates/main/images/sipka_zpet-cervena.gif");
		}
		if(me.attr('src') == '/templates/main/images/telefonek.gif') {
			me.attr('src', "/templates/main/images/telefonek-cerveny.gif");
		}

	});
	$('.fastbox img').bind('mouseout', function() {
		me = $(this);
		if(me.attr('src') == '/templates/main/images/obalka-cervena.gif') {
			me.attr('src', "/templates/main/images/obalka.gif");
		}
		if(me.attr('src') == '/templates/main/images/sipka_zpet-cervena.gif') {
			me.attr('src', "/templates/main/images/sipka_zpet.gif");
		}
		if(me.attr('src') == '/templates/main/images/telefonek-cerveny.gif') {
			me.attr('src', "/templates/main/images/telefonek.gif");
		}

	});

	$(".subCatImg").bind('mouseover', function(e) {
		if(subcat_list_type == 1) {
			$(this).find('img').attr("src", '/templates/main/images/subcat_ico_green.gif');
			$(this).find('a').css("color", '#8b2d12');
		}
	});
	$(".subCatImg").bind('mouseout', function(e) {
		if(subcat_list_type == 1) {
			$(this).find('img').attr("src", '/templates/main/images/subcat_ico_red.gif');
			$(this).find('a').css("color", '#383838');
		};
	});

	$(".switcher li").bind('mouseover', function(e) {
		$(this).css("background-color", '#383838');
		$(this).css("color", "white");
	});

	$(".switcher li").bind('mouseout', function(e) {
		if(($(this).text() - 1) != bigbannerpos) {
			$(this).css("background-color", '#f9f9f9');
			$(this).css("color", "black");
		}
	});

	$(".switcher li").bind('click', function(e) {
		if(window.event)
			e = window.event;
		var srcEl = e.srcElement ? e.srcElement : e.target;
		num = (srcEl.innerHTML) - 1;
		if(isNaN(num)) {
			num = (srcEl.innerText) - 1;
		}
		$('#bigbanner_images').trigger('stop');
		$('#bigbanner_images').trigger('goto', num);

	});

	$(".switcher li").each(function(index) {
		if(($(this).text() - 1) == 0) {
			$(this).css("background-color", '#383838');
			$(this).css("color", "white");
		}
	});

	$(".pBoxImage").each(function(index) {
		$(this).children('.obalka').prepend('<img class="lupa" src="/templates/main/images/lupa.png" alt="' + $(this).children(".pid").text() + '"/>');

		$(this).children('.obalka').children(".lupa").bind('click', function(e) {
			large_image(e.target.alt);
		});
	});
	
	$(".obrAtributy").each(function(index) {
		$(this).children('.polozkaImg').prepend('<img class="lupa" src="/templates/main/images/lupa.png"  />');

		$(this).children('.polozkaImg').children(".lupa").bind('click', function(e) {
			big_image($(this).parent().children("img:eq(1)").attr("src") );
			 
		});
	});
	
	$('.detailContent .obrazek').prepend('<img class="lupa" src="/templates/main/images/lupa.png">');

		$('.detailContent .obrazek').children(".lupa").bind('click', function(e) {
			big_image($(this).parent().children("img:eq(1)").attr("src")); 
		 
		$('.StockImg').prepend('<img class="lupa" src="/templates/main/images/lupa.png">');

		$('.StockImg').children(".lupa").bind('click', function(e) {
			big_image($(this).parent().children("img:eq(1)").attr("src")); });
			 
		
		}); 
			
});
function dokosiku() {
	window.location = "/kosik";
}

function closeConfirmation() {
	$("#cart_confirmation").hide();
}

function switcher_page(i) {
	$('#switcher li').attr('class', 'notactive');

}

if(screen.width > 11100) {
	var _hwq = _hwq || [];
	_hwq.push(['setKey', 'C48860D5942D9B4DFF8143EB9A9DB139']);
	_hwq.push(['setTopPos', '160']);
	_hwq.push(['showWidget', '21']);
	(function() {
		var ho = document.createElement('script');
		ho.type = 'text/javascript';
		ho.async = true;
		ho.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.heureka.cz/direct/i/gjs.php?n=wdgt&sak=C48860D5942D9B4DFF8143EB9A9DB139';
		var s = document.getElementsByTagName('script')[0];
		s.parentNode.insertBefore(ho, s);
	})();
}

// GOOGLE ANALYTICS
var _gaq = _gaq || [];
(function() {
	var a = document.createElement('script');
	a.type = 'text/javascript';
	a.async = true;
	a.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
	var s = document.getElementsByTagName('script')[0];
	s.parentNode.insertBefore(a, s)
})();
var _ga = {
	e : ['seznam.cz:q', 'seznam.cz:w', 'atlas.centrum.cz:q', 'searchatlas.centrum.cz:q', 'atlas.cz:q', 'centrum.cz:q', '1188.cz:q', 'jyxo.cz:q', 'mapy.cz:ssq', 'najisto.centrum.cz:what', 'takeit.cz:q', 'tiscali.cz:query', 'volny.cz:search', 'zacatek.cz:q', 'webhledani.cz:q', 'zlatestranky.cz:search', 'zoohoo.cz:q', '1.cz:q', 'akcni-cena.cz:search', 'b2bc.cz:XSearching', 'ceno.cz:q', 'cenyzbozi.cz:q', 'dobra-koupe.cz:searchtext', 'elektro.cz:w', 'elektrus.cz:h', 'eshop-katalog.cz:hledej', 'foxter.cz:search', 'heureka.cz:h[fraze]', 'hledam-zbozi.cz:q', 'hledejceny.cz:search', 'hyperceny.cz:q', 'ishopy.eu:search', 'koupis.cz:q', 'lepsiceny.cz:q', 'levnenakupy.cz:searchword', 'mojse.cz:search_text', 'monitor.cz:qw', 'naakup.cz:hledat', 'najdicenu.cz:ss', 'nakupte.cz:what', 'nejlepsiceny.cz:t', 'nejlepsinakupy.cz:q', 'nejnakup.cz:q', 'onlinezbozi.cz:search', 'porovnejcenu.cz:phrase', 'seznamobchodu.cz:search', 'seznamzbozi.cz:st', 'shoops.cz:s', 'shopy.cz:s', 'srovname.cz:hledat', 'srovnanicen.cz:q', 'srovnavadlo.cz:q', 'taxa.cz:keyword', 'usetrim.cz:q', 'vybereme.cz:q', 'zalevno.cz:q', 'zbozi.eshop-katalog.cz:hledej', 'zbozi.poptavky.cz:cond[fulltext]', 'zbozi.portik.cz:vyraz', 'zbozi.cz:q', 'atlas.sk:phrase', 'centrum.sk:q', 'azet.sk:q', 'azet.sk:sq', 'morfeo.sk:q', 'surf.sk:kw', 'szm.sk:ws', 'zoohoo.sk:q', 'zoznam.sk:s', 'cenoveinfo.sk:SearchProductName', 'e-nakupovanie.sk:searchword', 'heureka.sk:h[fraze]', 'najdicenu.sk:ss', 'najnakup.sk:q', 'nakup.24hod.sk:q', 'srovname.sk:hledat', 'superdeal.sk:q', 'tovar.sk:q', 'google:q', 'google:as_q', 'google:as_oq', 'google:as_epq', 'google:as_lq', 'google:as_rq', 'ananzi.co.za:qt', 'anzwers.com.au:search', 'araby.com:q', 'bbc.co.uk:q', 'britishinformation.com:search', 'club-internet.fr:q', 'elmundo.es:q', 'eniro.se:geo_area', 'excite.co.uk:q', 'excite.com:q', 'gigablast.com:q', 'hotbot.co.uk:query', 'hotbot.com:query', 'iafrica.funnel.co.za:q', 'icq.com:q', 'kelkoo:contextKeywords', 'looksmart.com:qt', 'maktoob.com:q', 'myway.com:searchfor', 'mywebsearch.com:searchfor', 'najdi.si:q', 'netsprint.pl:q', 'onet.pl:qt', 'orange.co.uk:q', 'rambler.ru:query', 'search.com:q', 'searcheurope.com:query', 'searchy.co.uk:search_term', 'sky.com:term', 'suche.web.de:su', 'tesco.net:q', 'tiscali.co.uk:query', 'virginmedia.com', 'q', 'wolframalpha.com:i', 'zinza.com:query'],
	create : function(a, b, c) {
		if(!b) {
			b = 'auto'
		}
		if(c) {
			c += '.'
		} else {
			c = ''
		}
		_gaq.push([c + '_setAccount', a]);
		_gaq.push([c + '_setDomainName', b]);
		_gaq.push([c + '_setAllowAnchor', true]);
		var s, i;
		for( i = this.e.length - 1; i >= 0; i--) {
			s = this.e[i].split(':');
			_gaq.push([c + '_addOrganic', s[0], s[1], true])
		}
	}
}
