$(document).ready(function() {
	$("#container-tabs > ul").tabs();
	$("#container-tabs").css("visibility", "visible");
	$(".jqZoom-container").css("visibility", "visible");
	$("a[rel=lightbox]").lightBox();

	$("#jqZoomHD").jqzoom({
		zoomWidth:		300,
		zoomHeight:		300,
		xOffset: 		15,
		yOffset:		0,
		title:			false,
		preloadText:	""
	});

	$("#load-360").click(function() {
		$(".product-thumbnail").hide();
		$("#container-360").css("left", "0px");
		swfobject.embedSWF($("#load-360").attr("rel"), "container-swf", "400", "400", "9.0.0", "expressInstall.swf");
		return false;
	});

	$("#close-360").click(function() {
		$("#container-360").css("left", "-9999px");
		$(".product-thumbnail").show();
		return false;
	});

	$(".jqZoomThumb").click(function() {
		$("#jqZoomHD").attr("href", $(this).attr("href"));
		$("#jqZoomLarge").attr("src", $(this).attr("rel"));
		return false;
	});

	$("#basket-add").click(function() {
		if ($("#productid").val().length > 0) {
			var objBasketPrice = document.getElementById("basketprice");
			objBasketPrice.innerHTML = parseInt(objBasketPrice.innerHTML) + parseInt($("#productprice").val());

			setCookie("Basket", getCookie("Basket") + $("#productid").val() + ",", null);
			setCookie("BasketPrice", objBasketPrice.innerHTML, null);

			rattleInit();
			setTimeout("stopRattle()", 500);
		} else {
			alert("Zvolte prosím velikost :-)");
		}
	});
});

var blnShake, intShake, objShake;

function rattleInit() {
	blnShake = true;
	intShake = 1;
	objShake = document.getElementById("basket-add");
	objShake.style.left = 0;
	objShake.style.top = 0;
	rattleImage();
}

function rattleImage() {
	if (blnShake) {
		switch (intShake) {
			case 1: objShake.style.top = parseInt(objShake.style.top) + 2 + "px"; break;
			case 2: objShake.style.left = parseInt(objShake.style.left) + 2 + "px"; break;
			case 3: objShake.style.top = parseInt(objShake.style.top) - 2 + "px"; break;
			case 4: objShake.style.left = parseInt(objShake.style.left) - 2 + "px";
		}

		if (intShake < 4) intShake++; else intShake = 1;
		setTimeout("rattleImage()",50);
	}
}

function stopRattle() {
	blnShake = false;
	objShake.style.left = 0;
	objShake.style.top = 0;
}
