//<script language="JavaScript">
//	KLIXO SLIDESHOW JAVASCRIPT LIBRARY - by Daniel Larsen
//	(c)2004 Klixo Ltd 2004. Some rights reserved:
//	Free for use by Klixo customers. All other use restricted, 
//	contact support@klixo.net.nz for details
//
// Dependancies:	klixo.js
// Instructions:	
//		The slideshow code will cycle through a slideshow of images using a 
//		predefined transistion effect and slide interval. A slide is changed
//		by resetting the src property of an IMAGE element with the ID 
//		"oSlideshowImage". The list of urls of slides to cycle through is
//		derived from an array of INPUT elements (typically of type="hidden")
//		named "SlideShowImageSrc".
//		Set constant mlSLIDE_INTERVAL to your desired slide interval.
//		The slideshow image must have a style of: 
//		img.slideshow
//		{
//			filter: progid:DXImageTransform.Microsoft.Fade(duration=1);
//		} 

var mlImageSrcIndex = 0;
var mlTimerHandle;
                    	
var mlSLIDE_INTERVAL = 5000; // Milliseconds

function Body_OnLoad()
{                				
	// Purpose:	Use this code for the Body Onload event to preload images and initialise
	//			the image events and timers.
	try
	{
		PreloadSlideImages();
		            				
		// Attach a state changed event to the customer image object
		oImage = GetElementByID("oSlideshowImage");
		            				
		if (oImage.attachEvent)
		{
		    oImage.attachEvent('onreadystatechange', oImage_OnReadyStateChange);
		}
		            				
		mlTimerHandle = StartTimeout(mlSLIDE_INTERVAL, Window_OnTimer);
	}
	catch(e)
	{
		HandleError(e);
	}
}

function kxInitSlideshow()
{
	// Purpose:	Use this code for the Body Onload event to preload images and initialise
	// the image events and timers. Copy of Body_OnLoad() above
	try
	{
		PreloadSlideImages();
		            				
		// Attach a state changed event to the customer image object
		oImage = GetElementByID("oSlideshowImage");
		switch (GetAgentType())        				
		{
		case	mlMSIE:
			if (oImage.attachEvent)
			{
		    oImage.attachEvent('onreadystatechange', oImage_OnReadyStateChange);
			}
			break;
		case	mlFIREFOX:
			if (oImage.addEventListener)
			{
				oImage.addEventListener('onreadystatechange', oImage_OnReadyStateChange, false);
			}
			break;
		}
		            				
		mlTimerHandle = StartTimeout(mlSLIDE_INTERVAL, Window_OnTimer);
	}
	catch(e)
	{
		HandleError(e);
	}
}
                    	
function oImage_OnClick()
{
	// Purpose:	Use this code for the onclick event of the image element if you would like
	//			a user to be able to cycle images manually by clicking on the image
	try
	{
		StopTimeout(mlTimerHandle);
		Window_OnTimer();
	}
	catch(e)
	{
	    HandleError(e);
	}
}
                    		
function Window_OnTimer()
{
	// Purpose:	Callback event for the timer, initialised by the Body_Onload procedure. Cycles
	//			an image and restarts the timer.
	var lCount = 0;
	                    		
	try
	{
		SlideImage(GetElementByID("oSlideshowImage"));

		lCount = GetElementsByName("SlideshowImageSrc").length;
	                    			
		if (lCount > 1)
		{
		    mlTimerHandle = StartTimeout(mlSLIDE_INTERVAL, Window_OnTimer);
		}
	}
	catch(e)
	{
		// Ignore error
		//HandleError(e);
	}
}

function oImage_OnReadyStateChange()
{
	// Purpose:	When an image has finished loading, this event is fired which will play
	//			the transition
	var oImage;
                    			
	try
	{
		oImage = GetElementByID("oSlideshowImage");
                        			
		if (oImage.readyState == "complete")
		{
		    if (oImage.filters)
		    {
		        oImage.filters[0].Play();
		    }
		}
	}
	catch(e)
	{
	    HandleError(e);
	}
}

function GetElementsByName(sName)
{
	return document.getElementsByName(sName);
}

function GetElementByID(sID)
{
	return document.getElementById(sID);
}

function PreloadSlideImages()
{
   // Purpose:	Starts background loading each image
   var lCount = 0;
   var i = 0;
                    		
   lCount = GetElementsByName("SlideshowImageSrc").length;
                    		
   if (lCount > 1)
   {
		lCount --;
				                			
		for (i = 0; i <= lCount; i++)
		{
		    PreLoadImage("../pics/customers/" + GetElementsByName("SlideshowImageSrc")[i].value);
		}
   }
}

function SlideImage(oImg)
{
   var lCount = 0;
                    		
   lCount = GetElementsByName("SlideshowImageSrc").length;
                    		
   if (lCount > 1)
   {
   	lCount --;
   	mlImageSrcIndex ++;
                    			
   	if (mlImageSrcIndex > lCount)
   	{
   		mlImageSrcIndex = 0;
   	}
                    		
   	if (oImg.filters)
   	{
   	    oImg.filters[0].Apply();
   	}
                    			
   	oImg.src = GetElementsByName("SlideshowImageSrc")[mlImageSrcIndex].value;
   }
}

// </script>