﻿function showAnimation()
{	
	var sImg1, sImg2;
	
	// if the current image is lower than the last image then we've gone too far, we need to loop back to the first image
	if(iCurrImg < 1)
	{
		iCurrImg = imgCount;
	}	
	
	// set the current image  (the one we're about to fade out)
	sImg1 = document.getElementById(imagePrefix + iCurrImg);
	
	
	// set the new image (the one we're about to fade in)
	if (document.getElementById(imagePrefix + (iCurrImg-1)))
	{
		sImg2 = document.getElementById(imagePrefix + (iCurrImg-1));
	}
	else
	{
		// if we get to the first image, go back to the first one
		sImg2 = document.getElementById(imagePrefix + imgCount);
	}
	
	// fade the images
	Effect.Fade(sImg1, { duration: 5.0});
	Effect.Appear(sImg2, { duration: 5.0});
		
	iCurrImg -= 1;		
			
	evt = setTimeout("showAnimation()", 5000);
}

function changeImg(img,url)
{
	clearTimeout(evt);
	
	var thisImg = document.getElementById(imagePrefix  + iCurrImg);

	// set the new image (the one we're about to fade in)
	if (document.getElementById(imagePrefix + (iCurrImg+1)))
	{
		sImg2 = document.getElementById(imagePrefix + (iCurrImg+1));
		iCurrImg++;
	}
	else
	{
	// if we get to the first image, go back to the first one
		sImg2 = document.getElementById(imagePrefix + 1);
		iCurrImg = 1;
	}
	

	
	if (thisImg.src.match(url + '$') == null)	// If this is a new image then fade the old one out and fade the new one in
	{
		sImg2.src = url;
		Effect.Fade(thisImg, { duration: 1.0});
		Effect.Appear(sImg2, { duration: 1.0});
	}
	
	thisImg = newImg;
}


