// Creates an ImageRotator object that controls the "rotation" of images on the page
// To be rotated, image elements must use the format:
//	    <img src="file1.gif" alt="" class="rotatingImage images:file2.gif,file3.gif" />
// The Microsoft-proprietary "blendTrans" filter is used to provide a smooth fade effect
var ImageRotator = function()
{
	var _transitionDuration = 3; // seconds
	var _transitionDelay = 5; // seconds
	var _rotatingImageList = new Array();
	var _rotatingImageIndex = 0;
	var _rotatorInterval = null;

	this.initialize = function()
	{
		var images = document.getElementsByTagName("img");
		for (var i = 0, n = images.length; i < n; i++)
		{
			if (images[i].className.match(/\brotatingImage\b/i))
			{
				images[i].imageList = images[i].className.match(/\bimages:([^ ]+)/i)[1].split(",");
				images[i].imageIndex = 0;
				if (images[i].filters)
				{
					images[i].style.filter = "blendTrans";
					try
					{
						images[i].filters[0].duration = _transitionDuration;
						_rotatingImageList.push(images[i]);
					}
					catch(exception)
					{
						// ignore
					}
				}
			}
		}
		if (_rotatingImageList.length > 0)
		{
			_rotatorInterval = window.setInterval(this.rotateImages, _transitionDelay * 1000); // milliseconds
		}
	}

	this.rotateImages = function()
	{
		var image = _rotatingImageList[_rotatingImageIndex];
		if (image.filters && image.filters[0] && image.imageIndex < image.imageList.length)
		{
			image.filters[0].apply();
			image.filters[0].play();
			image.src = image.imageList[image.imageIndex++];
		}
		_rotatingImageIndex = (_rotatingImageIndex + 1) % _rotatingImageList.length;
	}
}

ImageRotator.load = function()
{
	if (document.getElementsByTagName)
	{
		var imageRotator = new ImageRotator();
		imageRotator.initialize();
	}
}

// Attaches ImageRotator.load to window.onload
if (window.addEventListener) // DOM-compliant
{
	window.addEventListener("load", ImageRotator.load, false);
}
else if (window.attachEvent) // Microsoft
{
	window.attachEvent("onload", ImageRotator.load);
}
