// set the starting image.

//var i = Math.floor(Math.random()*9);			
var slideIndex = 0;

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

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

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

// the onload event handler that starts the fading.
function StartSlideShow() {
        $(image_slide[slideIndex ]).appear();
	play = setInterval('Play()',wait);
	//$('PlayButton').hide();
	//$('PauseButton').appear({ duration: 0});
								
}

function Play() {
	var imageShow, imageHide;

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

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

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

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

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

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