// Speed of the automatic slideshow
var slideshowSpeed = 5000;

// Variable to store the images we need to set as background
// which also includes some text and url's.
var photos = [ {
		"image" : "splash-banner-1.jpg",
	}, {
		"image" : "splash-banner-2.jpg",
	}, {
		"image" : "splash-banner-3.jpg",
	}, {
		"image" : "splash-banner-4.jpg",
	}, {
		"image" : "splash-banner-5.jpg",
	}
];

$(document).ready(function() {
		
	var interval;
	var activeContainer = 1;	
	var currentImg = 0;
	
	var navigate = function(direction) {
		
		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) {
		currentZindex--;
		
		$("#headerimg" + activeContainer).css({
			"background-image" : "url(uploads/webparts/splash/" + photoObject.image + ")",
			"display" : "block",
			"z-index" : currentZindex
		});
		
		$("#headerimg" + currentContainer).fadeOut();
	};
	
	navigate("next");
	
	interval = setInterval(function() {
		navigate("next");
	}, slideshowSpeed);
	
});
