﻿var imgCount = 0, iCurrImg, evt, isReverse = false;
var imagePrefix = "gimg";

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("delayAnimation()", 2000);
}

function nextImage()
{
    clearTimeout(evt);
	
	if(iCurrImg > 1)
	{			
	    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));		
	    }
	    else
	    {
	    // if we get to the first image, go back to the first one
		    sImg2 = document.getElementById(imagePrefix + imgCount);		
	    }
    	
	    Effect.Fade(thisImg, { duration: 0.1});
	    Effect.Appear(sImg2, { duration: 0.1});
    	
	    iCurrImg -= 1;
    }	    
}

function previousImage()
{            
    clearTimeout(evt);
	
	if(iCurrImg < imgCount)
	{				
	    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));		
	    }
	    else
	    {
	    // if we get to the first image, go back to the first one
		    sImg2 = document.getElementById(imagePrefix + 1);		
	    }
    	
	    Effect.Fade(thisImg, { duration: 0.1});
	    Effect.Appear(sImg2, { duration: 0.1});
    	
	    iCurrImg += 1;
    }
}

function playAnimation()
{
    showAnimation();
}

function pauseAnimation()
{
    clearTimeout(evt);
}



function delayAnimation()
{
    evt = setTimeout("showAnimation()", 7000);
} 

function imagePreloader()
{
     imageObj = new Image();

     var images = document.getElementById("ctl00_contentPL_slideshow_loadedimages").innerHTML;
	 var imageArray = images.split("|");
     
     for(i=1; i<imageArray.length; i++)
     {
          imageObj.src = "/img/db/" + imageArray[i];
     }
} 
