﻿
/********************************************************************************
* Functions to load, cache and rotate the banner image
********************************************************************************/
// set up some global variables
var _BannerImage;
var _CachedBannerImage = new Image();
var _CanRotate = false;

/*	Function to initialize the current image to be rotated	*/
function InitRotateImage(element)
{

	_BannerImage = element;

	// ensure that we're ready to start rotating images
	_CanRotate = typeof(_BannerImage) != 'undefined';
	_CanRotate = _CanRotate && (typeof(_RotatingImages) != 'undefined');
//	_CanRotate = _CanRotate && (_RotatingImages.length > 0);
    _CanRotate  = true
 
}

// Script to rotate through banner images
// expects _RotatingImages array to have been declared and defined
function LoadImageIntoCache()
{
	if (!_CanRotate)
	{
		return;
	}
		
	if (_BannerImage && _CachedBannerImage)
	{
	
		var index = Math.floor(Math.random() * _RotatingImages.length);
		
		_CachedBannerImage.src = _RotatingImages[index];		// load cached image
		_CachedBannerImage.onload = function () {SwapImages()};	// swap cached image when loaded
	}
}

function SwapImages()
{
	var canApplyFilter = _BannerImage.filters;

	if (canApplyFilter)
	{
		_BannerImage.filters.item(0).apply();
	}
	 
	_BannerImage.src = _CachedBannerImage.src;
	
	if (canApplyFilter)
	{
		_BannerImage.filters.item(0).play();
	}
	
	setTimeout("LoadImageIntoCache()", 3000);
}

/********************************************************************************
* END Functions to load, cache and rotate the banner image
********************************************************************************/

