/* ----------------------------------------------------------
	CROImages class
 	HTML Usage:

	1) 3 images for each button must be pre-defined using a global CROImage class instance
		create a separate javascript file (CROImage_defs.js) to contain the array of application
		specific class instances.  One array element for each button.

		roimages[0] = new CROImage("home", "images/roHome.gif", "images/btnHome.gif", "images/selHome.gif");
	
	2) Include this javascript and the image defs javascript in the	HTML header

		<SCRIPT LANGUAGE="javascript" src="CROImage.js"></SCRIPT>
		<SCRIPT LANGUAGE="javascript" src="CROImage_defs.js"></SCRIPT>
		
	3) The <A> tag must contain the onmouseover, onmoustout and onclick events calling the javascript functions

		<A HREF="home.html" 
			onmouseOver=getOn("home"); 
			onmouseOut=getOff("home"); 
			onClick=getDown("home");>
			
	4) the <IMG> tag must contain the matching tag name

		<IMG SRC= "images/btnHome.gif" BORDER=0 NAME="home">
   ---------------------------------------------------------- */


/* ----------------------------------------------------------
 	CROImages class
   ---------------------------------------------------------- */

/* CImage Constructor
 *	tagName:  		image tag name to reference this image instance
 *  onImageName:	mouse-over image
 *  offImageName:	normal image
 *  downImageName:	click image
 *
 * Save the tag name and create the image to pre-load the file
 */
function CROImage(tagName, onImageName, offImageName, downImageName) {
	this.tag = tagName;
	this.onImage = new Image();
	this.onImage.src = onImageName;
	this.offImage = new Image();
	this.offImage.src = offImageName;
	this.downImage = new Image();
	this.downImage.src = downImageName;
}

/* Preload Image: helper function to load images in the proper order
 * 	call this function to load images that do not have a corresponding roll-over
 */
function CPreloadImage(onImageName) {
	this.onImage = new Image();
	this.onImage.src = onImageName;
}

/* ----------------------------------------------------------
	Roll-over functions
   ---------------------------------------------------------- */
function getImageIndex(tagName)		// return the image index given the tag name
{
	for (i = 0; i < roimages.length; ++i)
	{
		if (roimages[i].tag == tagName)
		{
			return i;
		}
	}
	return -1;	// not found
}

function getOff(nom) {				// display the off (normal) image
	if (document.images) {
		var i = getImageIndex(nom);
		if (i > -1) {
			document.images[nom].src = roimages[i].offImage.src;
		}
	}
}

function getOn(nom) {				// display the on (rollover) image
	if (document.images) {
		var i = getImageIndex(nom);
		if (i > -1) {
			document.images[nom].src = roimages[i].onImage.src;
		}
	}
}

function getDown(nom) {				// display the down (click) image
	if (document.images) {
		var i = getImageIndex(nom);
		if (i > -1) {
			document.images[nom].src = roimages[i].downImage.src;
		}
	}
}

