/*
* Author:				Marco Kuiper (http://www.marcofolio.net/)
* Costumized:		Roy "QuickSilver" Bosland
*/
$(document).ready(function() {
	var activeContainer = 1;	
	var currentImg = 0;
	var animating = false;
	var navigate = function(direction) {

		if(direction == "next") {
			currentImg++;
			if(currentImg == photos.length + 1) {
				currentImg = 1;
			}
		} 
		
		var currentContainer = activeContainer;
		if(activeContainer == 1) {
			activeContainer = 2;
		} else {
			activeContainer = 1;
		}
		showImage(photos[currentImg - 1], currentContainer, activeContainer);
};
	
	var currentZindex = 2000;
	var showImage = function(photoObject, currentContainer, activeContainer) {
		animating = true;
		currentZindex--;
		
		$("#headerimg" + activeContainer).css({
			"background-image" : "url(" + photoObject.image + ")",
			"display" : "block",
			"z-index" : currentZindex
		});

		$("#headertxt").fadeOut(300, function () {$("#headertxt").css({"display" : "none"});});
		
		setTimeout(function() {
		$("#headertxt")
			.html("<span id=\"txt\">" + photoObject.title + "</span>");
		}, 500);
		
		$("#headerimg" + currentContainer).fadeOut(1000,function() {
			setTimeout(function() {
				if(photoObject.title) {
				$("#headertxt").fadeIn(300).css({"display" : "block"});
				}else {
				$("#headertxt").css({"display" : "none"});
				}
				animating = false;
			}, 500);
		});
	};
		
	navigate("next");
	interval = setInterval(function() {
		navigate("next");
	}, 7500);
	
});

$.fn.preload = function() {
	this.each(function(){
		$('<img/>')[0].src = this;
	});
} 
