/**
 * Classes for managing simple rollovers
 * @author	Valentin VALCIU, Lunatech
 * @remark	Must be invoked as JavaScript1.2
 * 
 */

 
/***************************************************************************
 * class ltRollover
 *
 */




/**
 * Constructor - creates a ltRollover object and initialize it
 *
 * @param	string strImgName		the <img> elements affected by the class has names matching this template; the pipe (|) character is replaced with elements from aNames to get the image name
 * @param	string strPathOff		template for the sources of the "mouse out" images; similar to strImgName
 * @param	string strPathOn		template for the sources of the "mouse over" images; similar to strImgName
 * @param	array aNames			the names of the <img> tags are made by replacing the pipe (|) character from strImgName with elements from this array; the corresponding file paths are made in a similar way using strPathOff and strPathOn
 */
function ltRollover(strImgName, strPathOff, strPathOn, aNames)
{
	// Constant properties
	this.strImgName = strImgName.split('|', 2);
	this.aPathOff = strPathOff.split('|', 2);
	this.aPathOn = strPathOn.split('|', 2);
	this.aNames = aNames;
	
	// Name of the selected image
	this.nameIgnore = '';
	
	// Private
	this.aImagesOff = new Array();
	this.aImagesOn = new Array();
	
	// Methods
	this.initImages = _ltRollover_initImages;
	this.changeImage = _ltRollover_changeImage;
	this.setIgnore = function (nameSelected) { this.nameIgnore = nameSelected; }
}

/**
 * Initialization function: preload images and store the name of the image to ignore when rolling over
 *
 * @param	string nameSelected		the name of the image (this.strImgName[0]) to be ignored by the rollover mechanism
 */
function _ltRollover_initImages(nameSelected)
{
	this.nameIgnore = nameSelected;
	
	if (! document.images)
		return false;
	
	var i, imgName;
	for (i = 0; i < this.aNames.length; i ++)
	{
		imgName = this.aNames[i];
		this.aImagesOff[imgName] = new Image();
		this.aImagesOff[imgName].src = this.aPathOff[0] + imgName + this.aPathOff[1];
		this.aImagesOn[imgName] = new Image();
		this.aImagesOn[imgName].src = this.aPathOn[0] + imgName + this.aPathOn[1];
	}
	
	return true;
}

/**
 * The rollover function
 *
 * @param	string imgName		the name of the image (without this.strImgName, key in this.aImagesOn, this.aImagesOff) to switch images
 * @param	bool onOff			true on "mouse over", false on "mouse out"
 */
function _ltRollover_changeImage(imgName, onOff)
{
	if (! document.images || (imgName == this.nameIgnore))
		return false;

	document.images[this.strImgName[0] + imgName + this.strImgName[1]].src = (onOff ? this.aImagesOn : this.aImagesOff)[imgName].src;
	return true;
}




/***************************************************************************
 * class ltStatusBar
 *
 */


/**
 * Constructor - creates a ltStatusBar object and initialize it
 *
 * @param	string strImgName		the <img> element used to show the status
 * @param	string strPathOff		"mouse out" image
 * @param	string strPathOn		template for the sources of the "mouse over" images; use the pipe (|) character as a placehoder
 * @param	array aNames			the names of the images to load
 */
function ltStatusBar(strImgName, strPathOff, strPathOn, aNames)
{
	// Constant properties
	this.strImgName = strImgName;
	this.aPathOff = strPathOff;
	this.aPathOn = strPathOn.split('|', 2);
	this.aNames = aNames;
	
	// Name of the selected image
	this.nameIgnore = '';
	
	// Private
	this.aImagesOff = new Image();
	this.aImagesOn = new Array();
	
	// Methods
	this.initImages = _ltStatusBar_initImages;
	this.changeImage = _ltStatusBar_changeImage;
	this.setIgnore = function (nameSelected) { this.nameIgnore = nameSelected; }
}

/**
 * Initialization function: preload images and store the name of the image to ignore when rolling over
 *
 * @param	string nameSelected		the name of the image (this.strImgName[0]) to be ignored by the rollover mechanism
 */
function _ltStatusBar_initImages(nameSelected)
{
	this.nameIgnore = nameSelected;
	
	if (! document.images)
		return false;
	
	this.aImagesOff.src = this.aPathOff;
	var i, imgName;
	for (i = 0; i < this.aNames.length; i ++)
	{
		imgName = this.aNames[i];
		this.aImagesOn[imgName] = new Image();
		this.aImagesOn[imgName].src = this.aPathOn[0] + imgName + this.aPathOn[1];
	}
	
	return true;
}

/**
 * The rollover function
 *
 * @param	bool onOff			true on "mouse over", false on "mouse out"
 * @param	string imgName		the id of the image to show; ignored when onOff is false
 */
function _ltStatusBar_changeImage(onOff, imgName)
{
	if (! document.images || (imgName == this.nameIgnore))
		return false;

	document.images[this.strImgName].src = (onOff ? this.aImagesOn[imgName] : this.aImagesOff).src;
	return true;
}

