YAHOO.namespace('AMCC');

var freezeObj = null;

function attachRollovers(e) {
	/* get all images of type rollover */
	var rolloverImgs = YAHOO.util.Dom.getElementsByClassName('rollover', 'img');
	
	/* if a mouse goes over one, highlight */
	YAHOO.util.Event.addListener(rolloverImgs, "mouseover", doRollover, Array(true));
	
	/* if a mouse goes out of one, return to normal state */
	YAHOO.util.Event.addListener(rolloverImgs, "mouseout", doRollover, Array(false));
}

function doRollover(e, thisObj) {
	/* find out which object is calling the event */
	curImgObj = YAHOO.util.Event.getTarget(e, true);
	
	/* however if an object was passed in, use it instead */
	if (thisObj.length > 1) {
		curImgObj = document.getElementById(thisObj[1]);
	}
	
	/* modify the image name based on wheather we are hovering over the image or not */
	/* check to see if we are allowed to modify the current object */
	if (freezeObj == curImgObj) { // do nothing
	} else { // roll out
		thisPath = modifyImageFilename(curImgObj.src, thisObj[0]);
		
		/* set the object's new source */
		curImgObj.src = thisPath;
	}
}

function modifyImageFilename(thisFileName, isOn) {
	/* remove the file type so that we're left with just the name */
	thisPath = thisFileName.substr(0, thisFileName.lastIndexOf("."));
	
	if (isOn) { // hover
		/* make sure the previous image is not sticky */
		if (thisFileName.lastIndexOf("_on") == -1) {
			thisPath = thisPath + "_on";
		}
	} else { // return to normal
		if (thisFileName.lastIndexOf("_on") > -1) {
			thisPath = thisFileName.substr(0, thisFileName.lastIndexOf("_on"));
		}
	}
	
	thisPath = thisPath + thisFileName.substr(thisFileName.lastIndexOf("."));
	
	return thisPath;
}

function openWin(thisURL, winName, atts) {
	var newWin = window.open(thisURL, winName, atts);
	newWin.focus();
}
		
function handleClick(e, tabsObj) {
	/* for each tab */
	for (idx = 0; idx < tabsObj.length; idx++) {
		/* is the tab selected? */
		tabObj = document.getElementById(tabsObj[idx][0]);

		if (tabsObj[idx][1]) { // yes, it is
			// freeze it!
			freezeObj = tabObj;
			tabObj.src = modifyImageFilename(tabObj.src, true);
		} else { // no it isn't, so deselect
			tabObj.src = modifyImageFilename(tabObj.src, false);
		}
	}
}

YAHOO.util.Event.addListener(window, "load", attachRollovers);