﻿var imgCount = 0, iCurrImg, evt;
var imageContainer = "ctl00_textPL_images";
var imagePrefix = "ssimg";

window.onload = function()
{			
	if (window.attachEvent) // for IE 
	{	    
		sfHover();
	}
	
	if(document.getElementById(imageContainer))
	{
		var images = document.getElementById(imageContainer).getElementsByTagName("img");
		
		imagePreloader(images);
		
		// Get the total number of images
		imgCount = images.length;
		
		// iCurrentImag is the image currently being displayed, as a default, set it to the first image
		iCurrImg = imgCount;
		
		if(images.length > 1)
		{			
			showAnimation();
		}
		else
		{
			clearTimeout(evt);
		}
	}
}

function imagePreloader( imageArray)
{
     imageObj = new Image();
     	 
     for(i=1; i<imageArray.length; i++)
     {		
		imageObj.src = imageArray[i].src;		
     }
} 

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: 7.0});
	Effect.Appear(sImg2, { duration: 7.0});
		
	iCurrImg -= 1;		
			
	evt = setTimeout("showAnimation()", 7000);
}

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;
}

function pauseAnimation()
{

}

function unpauseAnimation()
{

}



