/**
 * Create an instance of the Rollover object.<br>
 * Rollover will handle the details of image swaps in a nice clean
 * object-oriented way. Note that each Rollover that is constructed
 * is automatically added to a global hash named "rollovers", keyed
 * with the imageName.
 *
 * @author	mmathews@oxygen.com
 * @author	kfrank@oxygen.com
 * @version	1.0, 29 May 2001
 * @param	imageName	A String corresponding to the name attribute
 *						given to the image in the HTML. Optionally it
 *						could be an array of names.
 * @param	onImageSrc	The URL path to the image you wish to use as
 *						the "on image," presumably when the named
 *						image/s from param 1 is rolled over.
 * @param	offImageSrc	An optional URL path to the image you wish to
 *						use as the "off image," if blank the src of
 *						named image/s from param 1 is used.
*/
function Rollover(imageName, onImageSrc, offImageSrc) {

	if (arguments.length < 2)
		alert("USAGE: new Rollover(imageName, onImageSrc[, offImageSrc])")
	
	// handle case where first argument is an array of image names
	if (typeof imageName == "object") {
		for (i in imageName) {
			new Rollover(imageName[i], onImageSrc, offImageSrc)
		}
	}
	
	// populate instance properties
	this.imageName = imageName
	this.onImageSrc = onImageSrc
	this.offImageSrc = offImageSrc // optional
	
	// preload the onstate image
	var preloadTemp = new Image()
	preloadTemp.src = onImageSrc
	
	// create a global reference to the rollover collection
	if (window.rollovers == null) {
		rollovers = new Object()
	}
	rollovers[imageName] = this

}

/**
 * Set the src of the named image to be the "onImageSrc" passed into
 * this object's constructor.
 */

Rollover.prototype.on = function() {
	var docImage = (document.images)? document.images[this.imageName] : document.getElementById(this.imageName)
	
	// document may not have finished loading yet
	if (docImage == null) return false
	
	// in case where offstate image src is not defined use current image src
	if (this.offImageSrc == null) {
		this.offImageSrc = docImage.src
	}
	
	// do the image swap
	docImage.src = this.onImageSrc
}

/**
 * Set the src of the named image to be the "onffImageSrc" passed into
 * this object's constructor, or if none was pass in, to the src of the
 * image before its first "on()" was called.
 */
Rollover.prototype.off = function() {
	var docImage = (document.images)? document.images[this.imageName] : document.getElementById(this.imageName)
	
	// document may not have finished loading yet
	if (docImage == null) return false
	
	// this object may not have been turned "on()" yet
	if (this.offImageSrc == null) return false
	
	// do the image swap
	docImage.src = this.offImageSrc
}
