// JavaScript Document
	var photos = [ 
		{	"title" : "Background 3",
			"image" : "i/slides/Picture027.jpg"},	
		{	"title" : "Background 2",
			"image" : "i/slides/background3.jpg"},
		{	"title" : "Background 3",
			"image" : "i/slides/JC_44.jpg"},	
		{	"title" : "Background 3",
			"image" : "i/slides/Luxus_Large_Background.jpg"},	
		{	"title" : "Background 3",
			"image" : "i/slides/Picture041.jpg"},	
		{	"title" : "Background 3",
			"image" : "i/slides/Picture050.jpg"},	
		{	"title" : "Background 3",
			"image" : "i/slides/Picture059.jpg"},	
		{	"title" : "Background 3",
			"image" : "i/slides/Picture095.jpg"},	
		{	"title" : "Background 3",
			"image" : "i/slides/Picture130.jpg"},	
		{	"title" : "Background 3",
			"image" : "i/slides/Picture144.jpg"}	
	];


(function ($) {
	$.preLoadImages = function(imageList,callback) {
		var pic = [], i, total, loaded = 0;
		if (typeof imageList != 'undefined') {
			if ($.isArray(imageList)) {
				total = imageList.length; // used later
					for (i=0; i < total; i++) {
						pic[i] = new Image();
						pic[i].onload = function() {
							loaded++; // should never hit a race condition due to JS's non-threaded nature
							if (loaded == total) {
								if ($.isFunction(callback)) {
									callback();
								}
							}
						};
						pic[i].src = imageList[i]['image'];
					}
			}
			else {
				pic[0] = new Image();
				pic[0].onload = function() {
					if ($.isFunction(callback)) {
						callback();
					}
				}
				pic[0].src = imageList;
			}
		}
		pic = undefined;
	};
})(jQuery);


var activeContainer = 1;  
var currentImg = 0;
var playSlides = function() {
 
	currentImg++;
	if(currentImg == photos.length + 1) {
	 currentImg = 1;
	}
  
   // Check which container we need to use
   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--;
    
    // Set the background image of the new active container
    $("#main-bg-image" + activeContainer).css({
        "background-image" : "url(\"" + photoObject.image + "\")",
        "display" : "block",
		"z-index" : currentZindex
    });


    // Fade out the current container to reveal next
	$("#main-bg-image" + currentContainer).fadeOut(500);
};


