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

// The array of div names which will hold the images.
var image_slide = new Array('image-1', 'image-2', 'image-3', 'image-4', 'image-5', 'image-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 4 seconds by default.
var wait = 4000;

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

// 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++;
	}
	
	var textIn = i+1 + ' of ' + NumOfImages;
}

function Stop () {
	clearInterval(play);				
}

function GoNext() {
	
	var imageShow, imageHide;

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

}

function GoPrevious() {

	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)
	}
	
}


