var ShowLast = new Number(0);

var ShowId  = 0;      // call-back id
var ShowWait = 9000;	// interval (in ms) between images
var ShowFade = 4;      // duration (in seconds) for cross-fade effect between images (IE only; 0 = off)
var ShowOn = false;	// internal flag
var ShowIndex = new Number(0);

var ImagePath = new Array(ShowLast);

var NextImage = new Image();
var PrevImage = new Image();

function getPrevIndex()
{
	return (ShowIndex==0) ? ShowLast : (ShowIndex-1);
}

function getNextIndex()
{
	return (ShowIndex==ShowLast) ? 0 : (ShowIndex+1);
}

function doPrev()
{
	//load the main image from cache
	LoadImage(PrevImage);
	//set the new index
	ShowIndex = getPrevIndex();
	//update image cache
	cacheImages();
	
	return false;
}

function clickPrev()
{
	if(ShowOn) PauseShow();
	return doPrev();
}

function doNext()
{
	//load the main image from cache
	LoadImage(NextImage);
	//set the new index
	ShowIndex = getNextIndex();
	//update image cache
	cacheImages();

	//is the slide-show running?
	if(ShowOn)
	{	//set the call-back
		ShowId=window.setTimeout("doNext()",ShowWait);
	}
	
	return false;
}
	
function clickNext()
{
	if(ShowOn) PauseShow();
	return doNext();
}

function Run_Show()
{
	if(!ShowOn)
	{
		ShowOn = true;
		cacheImages();
		ShowId=window.setTimeout("doNext()",ShowWait);
	}
	return false;
}

function PauseShow()
{
	if(ShowOn)
	{
		ShowOn = false;
		window.clearTimeout(ShowId);
	}
	return false;
}

function cacheImages()
{
	PrevImage.src = ImagePath[getPrevIndex()];
	NextImage.src = ImagePath[getNextIndex()];
}

function LoadImage(img)
{	
	if(document.all && ShowFade>0)
	{
		document.images.MainImage.style.filter="blendTrans(duration=ShowFade)";
		document.images.MainImage.filters.blendTrans.Apply();
	}
	document["MainImage"].src = img.src;
	
	if(document.all && ShowFade>0)
	{
		document.images.MainImage.filters.blendTrans.Play();
	}
}