/* $Id: util.js 160 2004-07-20 15:20:59Z kibab $ */
global_images = [];

function initImageRollovers(rollover_suffix, class_name)
{
	var images;
	if(document.images)
	{
		images = document.images;
	}
	else { if(document.getElementsByTagName)
	{
		images = document.getElementsByTagName("img");
	}
	else
	{
		return;
	}}
	
	attachRollover(images, rollover_suffix, class_name);
	
	var inputs;
	if(document.getElementsByTagName)
	{
		inputs = document.getElementsByTagName("input");
	}
	else
	{
		return;
	}
	
	attachRollover(inputs, rollover_suffix, class_name);
			
}


function attachRollover(nodelist, rollover_suffix, class_name)
{
	var dotidx;
	var rollover_name;
	
	for(var i=0; i < nodelist.length; i++)
	{
		//if the item doesn't have the correct class name or if all items should be checked for rollovers
		if(nodelist[i].className == class_name || class_name == '')
		{
			//Figure out rollover name from the item name
			dotidx = nodelist[i].src.lastIndexOf('.');
			if(dotidx == -1)
				continue;
			rollover_name = nodelist[i].src.slice(0, dotidx) + rollover_suffix + '.' + nodelist[i].src.slice(dotidx+1);
			
			//Load the rollover image
			var tmp = new Image();
			
			//needed in IE in some cases.. investigate later.
			global_images[i] = tmp;
			
			tmp.origImg = nodelist[i]
			tmp.onload = function()
			{
				//set a couple of temp source attribs on the image object that resides in the page
				this.origImg.srcOrig = this.origImg.src;
				this.origImg.srcRoll = this.src;
				
				//setup the onMouseOver and onMouseOut functions
				this.origImg.onmouseover = function()
				{
					this.src = this.srcRoll;
				}
				
				this.origImg.onmouseout = function()
				{
					this.src = this.srcOrig;
				}
			}
			tmp.src = rollover_name;
			

		}
	}
}
