/**
 *	Mouseover.class.js
 *
 *	A simple class for implementing mouseovers in web pages.
 *
 *  INPUTS:
 *	imgName -	the name of the image that will change (not necessarily the one that will trigger the change)
 *	offImg -	the URL of the image to show when the mouse is out.
 *	onImg -		the URL of the image to show when the mouse is over the image.
 *
 *	Example:
 *  [script]
 *	var icon = new Mouseover("icon", "icon_on.gif", "icon_off.gif");
 *
 *	[html]
 *	<a href="somewhere.com" onMouseOver="icon.on();" onMouseOut="icon.off();">
 *	<img name="icon" src="icon_off.gif"> 
 *	</a> 
 */
function MouseOver(imgName, offImg, onImg) 
{
	this.imgName	= imgName;

	this.offImg 	= new Image();
	this.offImg.src = offImg;
	this.onImg 		= new Image();
	this.onImg.src 	= onImg;

	this.off = function () {
		document.images[this.imgName].src = this.offImg.src;
		};

	this.on	= function () {
		document.images[this.imgName].src = this.onImg.src;
		};
}

/**
 * 	A remote mouseover is a mouseover effect that affects an image that is
 *  different from the object on which the mouse is over.
 * 	@param	_imgName	the name of the image
 *			_imgArray	an array of arrays containing two elements: a string and 
 *						the URL of an image. The string can be used to refer to 
 *						its corresponding image. The 0th element is the image used 
 *						for the off state.
 *	@example
 *	[script]
 *	
 */
function RemoteMouseOver(_imgName, _imgArray)
{
    this.imgName    = _imgName;

    this.imgArray   = new Array();
    this.imgIndexArray = new Array();

    for(var i=0; i < _imgArray.length; i++)
    {
        this.imgArray[i] = new Image();
        this.imgArray[i].src = _imgArray[i][1];

        this.imgIndexArray[i] = _imgArray[i][0];
    }

	/**
	 *	The mouse is on the object; replace the image
	 *	with the image specified by _imgIndex.
	 * 	@param	_imgIndex	a number or a string. If its a number
	 *						then the number indicates the index of the image to use.
	 *						Otherwise, find the write image according to the string.
	 */
    this.on = function (_imgIndex) {
		var index = 0;

		if(isNaN(_imgIndex)) {
			for(var j=0; j < this.imgIndexArray.length; j++) {
				if(_imgIndex == this.imgIndexArray[j]) {
					index = j;
					break;
				}
			}
		} else {
			index = _imgIndex;
		}

        document.images[this.imgName].src = this.imgArray[index].src;
	};
	
	/**
	 * Revert the image to an off state.
	 */
	this.off = function () {
		document.images[this.imgName].src = this.imgArray[0].src;
	};
}
