/*
	imgswaper.js
	class to pre-load images and to swap them to creat roll-over effects
	!!!!!!!!!!!!
	NOTE:
		The mouseover image's path is stored in the name attribute of the img tag and uses this to preload it too.
	!!!!!!!!!!!!
*/

function ImgSwaper(i)
{
	if ( typeof(i) == 'string' )
		this.theImg = document.getElementById(i);
	else
		this.theImg = i;
		
	var temp = new Image();
	temp.src = this.theImg.name;
	this.regSwapImg();
}

ImgSwaper.prototype.swapImg = function()
{
	var temp = this.theImg.src;
	this.theImg.src = this.theImg.name;
	this.theImg.name = temp;
}

ImgSwaper.prototype.regSwapImg = function()
{
	var theObj = this;
	addEvent(this.theImg.parentNode, 'mouseover', function() { theObj.swapImg.call(theObj); } );
	addEvent(this.theImg.parentNode, 'mouseout', function() { theObj.swapImg.call(theObj); } );
}

ImgSwaper.prototype.toString = function()
{
	return "img.src = " + this.theImg.src + ", img.name = " + this.theImg.name;
}

ImgSwaper.initImgSwap = function(imgList)
{		
	var imgs = document.getElementsByTagName('img');
	
	for ( var i = 0; i != imgs.length; i++ )
	{
		if ( imgs[i].parentNode.nodeName.toLowerCase() == 'a' && imgs[i].name != "" )
		{
			imgList[i] = new ImgSwaper(imgs[i]);
		}
	}
}

if ( document.getElementsByTagName && document.getElementById )
{
	var imgs = new Array();
	
	addEvent(window, 'load' , function() { ImgSwaper.initImgSwap(imgs); });
}