// set the starting image.
var b = 0;	
var cur = 0;
// The array of div names which will hold the images.
var image_slide = new Array('bc1', 'bc2', 'bc3', 'bc4');
// The number of images in the array.
var NumOfImages = image_slide.length;
// The time to wait before moving to the next image. Set to 4 seconds by default.
var wait = 10000;
var play = null;

// The Fade Function
function SwapImage(x,y) {	
	cur = x;
	if(y >= 0)
	{
		$(image_slide[y]).fade({ duration: 0.0 });
		$('bm'+(y+1)).className = 'bm'+(y+1);
	} 
	if(x >= 0)
	{
		$(image_slide[x]).appear({ duration: 0.5 });
		$('bm'+(x+1)).className = 'bm'+(x+1)+'a';
	}
}

function SwapBanner(banner)
{
	if(play !== null && play !== undefined )
		clearInterval(play);

	SwapImage(banner, cur);
}

function StartSlideShow() {
	play = setInterval('Play()',wait);
}

function Play() {
	var imageHide;

	imageShow = b+1;
	imageHide = b;
	
	if (imageShow == NumOfImages) {
		SwapImage(0, imageHide);	
		b = 0;	
		clearInterval(play);
	} else {
		SwapImage(imageShow, imageHide);			
		b++;
	}
}

Event.observe(window, "load", function(){
	StartSlideShow();
});