// set the starting image.
var i = 0;			
	
// The time to wait before moving to the next image. Set to 4 seconds by default.
var wait = 6000;

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

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

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;
	updatecounter();
}

function Stop () {
	clearInterval(play);				
}

function GoNext() {
	clearInterval(play);
	var imageShow, imageHide;

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

	updatecounter();
}

function GoPrevious() {
	clearInterval(play);
	var imageShow, imageHide;
				
	imageShow = i-1;
	imageHide = i;
	
	if (i == 0) {
		SwapImage(NumOfImages-1,imageHide);	
		i = NumOfImages-1;		
	} else {
		SwapImage(imageShow,imageHide);			
		i--;
	}
	
	updatecounter();
}

function updatecounter() {
	var textIn = i+1 + ' of ' + NumOfImages;
}



