// set the starting image.
var i = 0;
var cur_image = 0;

// The array of div names which will hold the images.
var div_slide = new Array('header_1', 'header_2');

// The number of images in the array.
var NumOfDivs = div_slide.length;
var NumOfImages = image_slide.length;

// The Fade Function
function SwapDiv(x, y) {
	$("#"+div_slide[x]).fadeIn(fadeSpeed, "linear");
	$("#"+div_slide[y]).fadeOut(fadeSpeed, "linear");
}

// the onload event handler that starts the fading.
function StartSlideShow() {
	play = setInterval('Play()',wait);
}

function Play() {
	var divShow, divHide;
	var imageShow, imageHide;

	divShow = i+1;
	divHide = i;

	i++;
	if (divShow == NumOfDivs) {
		divShow = 0;
		i = 0;
	}
	
	LoadNextImage(divShow);
	SwapDiv(divShow, divHide);
}

function LoadNextImage(div) {
	if(cur_image+1 == NumOfImages)
		cur_image = -1;
	
	$('#'+div_slide[div]).css("background-image", "url('files/" + image_slide[cur_image+1] + "')");
	cur_image++;
}

$(document).ready(function(){StartSlideShow();});
