current = 0;
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] = links[current][0];
		$("#layer1").hide(1).css("background-image", "url(" + currentImage +")").fadeIn(500, function() {
			$("#layer2").hide(1).css("background-image", "url(" + currentImage +")").fadeIn(500, function() {
				currentLink[1] = links[current][1]; 
				$("#layer3").hide(1).css("background-image", "url(" + currentImage +")").fadeIn(500, function() {
					currentLink[2] = links[current][2]; 
					$("#layer4").hide(1).css("background-image", "url(" + currentImage +")").fadeIn(500, function() {
						currentLink[3] = links[current][3]; 
						if (imageSet > 1) {
							var img = new Image();
							nextImg = (current)%2+1;
							$(img).attr("src", currentPath + currentPage + nextImg + ".jpg").load(showProduct(5000));
						}
					});
				});
			});
		});
	});
}

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