current = 0;
currentPage = "Home";
last = 0;
timeout=0;
currentPath = "/images/" + currentPage + "/";
currentLink = ['','','','','','',''];

$(document).ready(function() {
	initial();
	$('#playerWrap a').each(function(index){
		$(this).bind("click", function(){
			if (currentLink[index] != ''){
				window.location.href = currentLink[index];
			}
		});
	});
});

function showProduct(delay) {
	current = (current)%2+1;
	currentImage = currentPath + currentPage + current + ".jpg";
	$("#layer1").animate({opacity: 1},delay, "linear", function() {
		currentLink[0] = urls[current][0];
		$("#layer1").hide(1).css("background-image", "url(" + currentImage +")").fadeIn(500, function() {
			$("#layer2").hide().css("background-image", "url(" + currentImage +")").fadeIn(500, function() {
				currentLink[1] = urls[current][1];
				$("#layer3").hide().css("background-image", "url(" + currentImage +")").fadeIn(500, function() {
					currentLink[2] = urls[current][2];
					$("#layer4").hide().css("background-image", "url(" + currentImage +")").fadeIn(500, function() {
						currentLink[3] = urls[current][3];
						$("#layer7").hide().css("background-image", "url(" + currentImage +")").fadeIn(500, function() {
							currentLink[4] = urls[current][4];
							$("#layer6").hide().css("background-image", "url(" + currentImage +")").fadeIn(500, function() {
								currentLink[5] = urls[current][5];
								$("#layer5").hide().css("background-image", "url(" + currentImage +")").fadeIn(500, function() {
									currentLink[6] = urls[current][6];
									var img = new Image();
									nextImg = (current)%2+1;
									$(img).attr("src", currentPath + currentPage + nextImg + ".jpg").load(showProduct(5000));
								});
							});
						});
					});
				});
			});
		});
	});
}

function initial() {
	$("#layer2").fadeIn(500, function(){
		$("#layer6").fadeIn(500, function(){
			$("#layer4").fadeIn(500, function() {
				$("#layer5").fadeIn(500, function() {
					$("#layer1").fadeIn(500, function() {
						$("#layer3").fadeIn(500, function() {
							$("#layer7").fadeIn(500, function(){
								var img = new Image();
								nextImg = (current)%2+1;
								$(img).attr("src", currentPath + currentPage + nextImg + ".jpg").load(showProduct(2000));
							});
						});
					});
				});
			});
		});
	});
}
