// start the slideshow when the window loads
Event.observe(window, 'load', StartSlideShow, false);

// set the starting image.
var i = 0;			

// The array of div names which will hold the images.
var image_slide = new Array('home-show-1', 'home-show-2', 'home-show-3', 'home-show-4', 'home-show-5', 'home-show-6');

// The number of images in the array.
var NumOfImages = image_slide.length;

// The time to wait before moving to the next image. Set to 3 seconds by default.
var wait = 4000;

// The Fade Function
function SwapImage(x,y) {
	Effect.Appear(image_slide[x], {duration: 1.5 });
	Effect.Fade(image_slide[y], {duration: 1.5});
}

// the onload event handler that starts the fading.
function StartSlideShow() {
	play = setInterval('Play()',wait);		
}

function Play() {
	var imageShow, imageHide;

	imageShow = i+1;
	imageHide = i;
	
	if (imageShow == NumOfImages) {
		SwapImage(0,imageHide);	
		i = 0;					
	} else {
		SwapImage(imageShow,imageHide);			
		i++;
	}
}

function Stop () {
	clearInterval(play);				
	// $('PlayButton').appear({ duration: 0});
	// $('PauseButton').hide();
}

function GoNext() {
	clearInterval(play);
	// $('PlayButton').appear({ duration: 0});
	// $('PauseButton').hide();
	
	var imageShow, imageHide;

	imageShow = i+1;
	imageHide = i;
	
	if (imageShow == NumOfImages) {
		SwapImage(0,imageHide);	
		i = 0;					
	} else {
		SwapImage(imageShow,imageHide);			
		i++;
	}
}

function GoPrevious() {
	clearInterval(play);
	// $('PlayButton').appear({ duration: 0});
	// $('PauseButton').hide();

	var imageShow, imageHide;
				
	imageShow = i-1;
	imageHide = i;
	
	if (i == 0) {
		SwapImage(NumOfImages-1,imageHide);	
		i = NumOfImages-1;		
		
		//alert(NumOfImages-1 + ' and ' + imageHide + ' i=' + i)
					
	} else {
		SwapImage(imageShow,imageHide);			
		i--;
		
		//alert(imageShow + ' and ' + imageHide)
	}
}

