/** Author:Marco Kuiper (http://www.marcofolio.net/) */
var slideshowSpeed = 5000;
var photos = [{"image":"wallpapers/home-wallpaper-1.jpg"},{"image":"wallpapers/home-wallpaper-2.jpg"}, {"image":"wallpapers/home-wallpaper-3.jpg"},{"image":"wallpapers/home-wallpaper-4.jpg"}];

$(document).ready(function() {
	$("#back").click(function() { stopAnimation(); navigate("back"); });
	$("#next").click(function() { stopAnimation(); navigate("next"); });
	var interval;
	$("#control").toggle(function(){ stopAnimation(); }, function() {$(this).css({ "background-image" : "url(image/home/btn_pause.png)" });
	navigate("next");
	interval = setInterval(function() { navigate("next"); }, slideshowSpeed);
});
	
var activeContainer = 1;	
var currentImg = 0;
var animating = false;
var navigate = function(direction) {
	if(animating) { return; }
	if(direction == "next") { currentImg++; if(currentImg == photos.length + 1) { currentImg = 1;} }
	else { currentImg--; if(currentImg == 0) { currentImg = photos.length; } }
	var currentContainer = activeContainer;
	if(activeContainer == 1) { activeContainer = 2; }
	else { activeContainer = 1; }
	showImage(photos[currentImg - 1], currentContainer, activeContainer);
};
	
var currentZindex = -1;
var showImage = function(photoObject, currentContainer, activeContainer) {
	animating = true;
	currentZindex--;
	$("#slideholder" + activeContainer).css({ "background-image" : "url(image/" + photoObject.image + ")","display" : "block","z-index" : currentZindex });
	$("#slideholder" + currentContainer).fadeOut(function() { setTimeout(function() { animating = false; }, 500);});
};
	
var stopAnimation = function() { $("#control").css({ "background-image" : "url(image/home/btn_play.png)" }); clearInterval(interval);};
navigate("next");
interval = setInterval(function() { navigate("next");}, slideshowSpeed);});
