var i = 0;

// The Fade Function
function SwapImage(x,y) {
	$(image_slide[y]).fade({duration: 0.5});
	setTimeout('$(image_slide[' + x + ']).appear({ duration: 0.5 });', 500);
	if(typeof(description_slide)!="undefined")
	{
		$(description_slide[y]).fade({duration: 0.5});
		setTimeout('$(description_slide[' + x + ']).appear({ duration: 0.5 });', 500);
	}
}

// the onload event handler that starts the fading.
function StartSlideShow() {
	//play = setInterval('Play()',wait);
	play=null;
}

function Play() {
	var imageShow, imageHide;

	imageShow = i+1;
	imageHide = i;
	
	if (imageShow == NumOfImages) {
		SwapImage(0,imageHide);	
		i = 0;					
	} else {
		SwapImage(imageShow,imageHide);			
		i++;
	}
}

function GoNext() {
	if(typeof play != "undefined") {
		clearInterval(play);
	}
	
	var imageShow, imageHide;

	imageShow = i+1;
	imageHide = i;
	
	if (imageShow == NumOfImages) {
		SwapImage(0,imageHide);	
		i = 0;					
	} else {
		SwapImage(imageShow,imageHide);			
		i++;
	}
}

function GoPrevious() {
	if(typeof play != "undefined") {
		clearInterval(play);
	}

	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)
	}
}

function GoIndex(image_index) {
	if(typeof play != "undefined") {
		clearInterval(play);
	}

	var imageShow, imageHide;

	imageShow = image_index;
	imageHide = i;
	i = image_index;
	SwapImage(imageShow,imageHide);
}
