
// ************************** VARIABLES ******************************
var parameters = '';
var busy = false;
var background = 0;
var background_delay = 7000;



$(document).ready(function(){
	
	
});	



function slideSwitch(next_photo) {

	function changeBackground() {
		
		if ( $("#background1").css('display') == 'none') {

			$("#background1").attr('src',backgrounds[background]);
			$("#background2").fadeOut(1000);
			$("#background1").fadeIn(1000);
			
			
		} else {
	
			$("#background2").attr('src',backgrounds[background]);
			$("#background1").fadeOut(1000);
			$("#background2").fadeIn(1000);
			
		}
	
	}
		
	if (!busy){
		
		busy = true;		
		clearTimeout(timer);
		timer = setInterval( "slideSwitch(1)", background_delay);
		
		
		if (!next_photo) {
			
			if (background==0) background = backgrounds.length-1;
			else background--;
			
		} else {
			
			if (background==(backgrounds.length-1)) background = 0;
			else background++;		
			
		}		
		
		bckimg= new Image();
		bckimg.src= backgrounds[background];
	
		// For IE:
		if ($.browser.msie) {
			
			function testImg(){
		        if(bckimg.complete != null && bckimg.complete == true){ 
		                changeBackground();
		                return;
		        }
			
		        setTimeout(testImg, 300);
			}
			setTimeout(testImg, 300);
		
		}
		else bckimg.onload = changeBackground;
		
		// Preload next image!
		bckimgnew= new Image();
		bckimgnew.src= backgrounds[background+1];
		
		busy=false;
		
	}
	else { clearTimeout(timer); timer = setTimeout( "slideSwitch(1)", 1500);}
}


$(function() {
    timer = setInterval( "slideSwitch(1)", background_delay);
	
});



	


