/**
 * Rollovers.js
 * by Jason Winnebeck
 * Date Started:  12/27/01
 * Version: 2.0 on 1/ 8/02
 */

/**
 * This function disables the rollover from being clicked, and makes the rollover
 * appear disabled.  Unforunately I have not found a way to remove the hand cursor
 * that makes it appear to be a link.
 * The image must follow the naming scheme that Fireworks uses, where the up image
 * is called *.gif and the associated down image *_f2.gif where the * is some image
 * name.
 * If the rollover had already been disabled, or the named object does not exist,
 * this function has no effect.
 * This function uses the Dreamweaver rollover functions to help it, but the
 * MM_findObj method is easy to copy over.
 * Parameters:
 *  oName: Pass it the name of the image (the name attribute in the img tag).
 *  showDown: if true or non-existant, shows the picture's down image
 *  disableClick: if true or non-existant, stops the user from clicking it.
 */
function disableRollover(oName, showDown, disableClick) {
	//Set defaults
	if (showDown == null)
		showDown = true;
	if (disableClick == null)
		disableClick = true;
		
	var x;
	if ( (x=MM_findObj(oName) ) != null) {
		//Add the rollover to the disabled array if not already disabled.
		if (disableClick && x.isClickDisabled == null) {
			if (!document.mmDisabled)
				document.mmDisabled = new Array;
			document.mmDisabled[document.mmDisabled.length] = x.name;
			x.isClickDisabled = true;
			x.parentElement.style.cursor = "default";			
		}
		
		//Insert _f2 into the image URL if showDown and it is not already down.
		if (showDown && x.oldSrc == null) {
			var insertPos = x.src.lastIndexOf(".");
			if (insertPos > 0) {
				x.oldSrc = x.src;
				x.oldOSrc = x.oSrc;
				var first = x.src.substring(0, insertPos);
				var last = x.src.substring(insertPos, x.src.length);
				x.oSrc = x.src = first + "_f2" + last;
			}
		}
	}
}

/**
 * This undoes any actions done by the previous function.  Like disableRollover,
 * you can call this function even if the button is already enabled.
 */
function enableRollover(oName, showUp, enableClick) {
	//Set Defaults
	if (showUp == null)
		showUp = true;
	if (enableClick == null)
		enableClick = true;
		
	var x;
	if ( (x=MM_findObj(oName) ) != null) {
		//Do enableClick functionality
		if (enableClick) {
			for (var i=0; i < document.mmDisabled.length; i++)
				if (document.mmDisabled[i] == oName)
					document.mmDisabled[i] = "_deleted_";
			x.isClickDisabled = null;
		}
			
		//Do showUp functionality
		var x;
		if (showUp) {
			if (x.oldSrc != null) {
				x.src = x.oldSrc;
				x.oSrc = x.oldOSrc;
				x.oldSrc = x.oldOSrc = null;
			}
		}
	}
}

/**
 * The global event handler for onclick which destroys click events on disabled
 * rollovers before they reach the link.  This only works in MSIE 4+.
 * This cannot exist with another handler, but in the future chaining event
 * handlers might be added.
 */
function disabledRolloverHandler() {
	if (document.mmDisabled)
		for (var i=0; i < document.mmDisabled.length; i++)
			if (document.mmDisabled[i] == event.srcElement.name)
				return false;
	return true;
}

document.onclick=disabledRolloverHandler;
