/* All dynamic images must have in common the same postfix in order for this script to
   work properly.  So images alpha.jpg and beta.jpg have their partner images for the
   mouseOver events alpha_over.jpg and beta_over.jpg in the same folder, respectively.
   In this example, "_over" would be the defined imgPostfix. */
var imgPostfix = "_over";
var imgCache = new Array();

/* Use this function for the onMouseOver and onMouseOut functions in an img tag.  Pass
   the image object to the function, such as "imageSwap(this);" */
function imageSwap(imgObj)
{
	if (!imgObj.active)
	{
		imgObj.oSrc = imgObj.src;
		imgObj.src = imageAlternate(imgObj.src);
	}
	else
		imgObj.src = imgObj.oSrc;
	imgObj.active = !imgObj.active;
}

/* With this function pass however many original image names you require and it will
   preload the mouseOver event images into the browser.  You may leave the argument
   list empty if you wish to preload a mouseOver event image for every image already
   on the page.  */
function preloadImages()
{
	var funcArgs = preloadImages.arguments;
	if (funcArgs.length == 0)
	{
		var newArgs = new Array();
		funcArgs = document.getElementsByTagName("img");
		for (var i = 0; i < funcArgs.length; i++)
			newArgs[i] = funcArgs[i].src;
		funcArgs = newArgs;
	}
	for (var i = 0; i < funcArgs.length; i++)
	{
		if (funcArgs[i].indexOf("#") != 0)
		{
			imgCache[imgCache.length] = new Image;
			imgCache[imgCache.length - 1].src = imageAlternate(funcArgs[i]); 
		}
	}
}

/* This function is used by the others functions only. */
function imageAlternate(src)
{
	return src.substr(0, src.lastIndexOf(".")) + imgPostfix + src.substr(src.lastIndexOf("."))
}
