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

// The array of div names which will hold the images.
//var image_slide = new Array('image-0', 'image-1', 'image-2');

// 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 = 4000;

// The Fade Function
function SwapImage(x,y) {		
	if($('image-'+x) !=undefined){
		$('image-'+x).show();
		$('image-'+y).hide();
	}
	//$(image_slide[x]).show();
	//$(image_slide[y]).hide();
}

// the onload event handler that starts the fading.
function StartSlideShow() {
	play = setInterval('Play()',wait);
	if($('PlayButton')!=undefined) {
		$('PlayButton').hide();
		$('PauseButton').show();
	}
}

function Play() {
	var imageShow, imageHide;

	imageShow = i+1;
	imageHide = i;	
	if($('image-'+imageShow)== undefined) {
		SwapImage(0,imageHide);	
		i = 0;					
	} else {
		SwapImage(imageShow,imageHide);			
		i++;
	}
}

function Stop () {
	clearInterval(play);				
	$('PlayButton').show();
	$('PauseButton').hide();
}

function GoNext(NumOfImages) {
	clearInterval(play);
	$('PlayButton').show();
	$('PauseButton').hide();
	
	var imageShow, imageHide;

	imageShow = i+1;
	imageHide = i;
	
	if($('image-'+imageShow)==undefined) {
		SwapImage(0,imageHide);	
		i = 0;					
	} else {
		SwapImage(imageShow,imageHide);			
		i++;
	}
}

function GoPrevious(NumOfImages) {
	clearInterval(play);
	$('PlayButton').show();
	$('PauseButton').hide();

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