////////////////////////////////////////////////////////////////////////////////
//
// AutoRollover
// Copyright (C) 2004 Homeboyz Interactive, Inc.
// License: BSD
// $Id: autoRollover.js,v 1.5 2004/04/13 15:51:45 tduffey Exp $
//
////////////////////////////////////////////////////////////////////////////////
//
// Automatically turn images with class "autoRollover" into
// rollover images where the hover-state image is filename_hover.ext,
// e.g. if you have:
//
//	<img src="images/foo.gif" class="autoRollover" />
//
// then there must be an image called "images/foo_hover.gif"
//
// The script does not check if the hover image exists!
//
////////////////////////////////////////////////////////////////////////////////

function autoRollover()
{
	if (document.getElementById)
	{
		var searchRegex = /autoRollover/i;
		var images = document.getElementsByTagName("img");

		for (var i = 0; i < images.length; i++)
		{
			// If image has class "autoRollover"
			if (-1 != images[i].className.search(searchRegex))
			{
				var src = images[i].src;
				var lastDotPosition = src.lastIndexOf(".");
				var srcExt = src.substring(lastDotPosition, src.length);

				var hoverSrc = src.substring(0, lastDotPosition) + "_hover" + srcExt;

				images[i].hImg = new Image();
				images[i].hImg.src = hoverSrc;

				images[i].oImg = new Image();
				images[i].oImg.src = images[i].src;

				images[i].onmouseover = function()
				{
					this.src = this.hImg.src;
				}

				images[i].onmouseout = function()
				{
					this.src = this.oImg.src;
				}
			}
		}
	}
}

if (typeof window.addEventListener != "undefined")
	window.addEventListener("load", autoRollover, false);
else if (typeof document.addEventListener != "undefined")
	document.addEventListener("load", autoRollover, false);
else if (typeof window.attachEvent != "undefined")
	window.attachEvent("onload", autoRollover);
else
{
	if (typeof window.onload == "function")
	{
		window.currentOnload = window.onload;

		window.onload = function()
		{
			window.currentOnload();
			autoRollover();
		}
	}
	else
		window.onload = autoRollover;
}