// Amanda Birmingham's heavily-modified version of
// Bill Weinman's Common JavaScript Rollover Engine
// As described in "Creative HTML Design", by Lynda and Bill Weinman
// (c) 1997 Bill Weinman
// 
// You are free to use this script, and modify it to 
// your heart's content. You must leave this entire header
// --including this notice--intact, and make sure there 
// is a reference to our web site: <http://www.htmlbook.com/>. 
// Version 1.0.  First release with Creative HTML Design

//global variables
var gblnOkay = false; // this MUST be the first line of code! ... it prevents the rollovers from happening before init
var garrRollImages = new Array();

//THESE THINGS CHANGE -- variables specific to each use of this script
//--------------------------------------------------------------------
gstrOverPrefix = "over-";
gstrOutPrefix = "out-";
//--------------------------------------------------------------------

function initRollovers(strImagePath, arrImageNames) {
	//local variables
	var strBaseName;
	var intNameIndex, strCurrentArray;
	var strOverName, strOutName;
	var strOverPrefix = gstrOverPrefix;
	var strOutPrefix = gstrOutPrefix;

	//should be a check here: if the strImagesPath doesn't contain a slash
	//as the last character, throw an error

	//this will work in "Mozilla" 3+ (includes MSIE 4)
	//set the okay to true for those browsers; else, leave it false (as it was defined)
	if (navigator.appCodeName == "Mozilla" && parseInt(navigator.appVersion) >= 3) {gblnOkay = true;} 
	
	//loop through all the base image names
	for (intNameIndex = 0; intNameIndex < arrImageNames.length; intNameIndex++) {
	  //split the name on the "."
	  strBaseName = arrImageNames[intNameIndex].split(".")[0];
	
	  //create name for array that will hold the on and off images, and create the names for those images
	  strCurrentArray = "arr" + strBaseName;
	  strOverName  = strOverPrefix + arrImageNames[intNameIndex];
	  strOutName = strOutPrefix + arrImageNames[intNameIndex];
	  
	  //this uses eval to create variables and to pre-load the images. 
	  eval("var " + strCurrentArray + "= new Array();");
	  eval(strCurrentArray + "['out']= new Image();");
	  eval(strCurrentArray + "['over']= new Image();");
	  eval(strCurrentArray + "['out'].src = '" + strImagePath + strOutName + "';");
	  eval(strCurrentArray + "['over'].src = '" + strImagePath + strOverName + "';");
	  
	  //put this little array into the global images array
	  eval("garrRollImages['" + strBaseName + "'] = " + strCurrentArray + ";");
	} //next base image
} //end function initRollovers

// the mouseEvent function
function rollImage(strImageName, strAction) {
	//check if the browser supports this action
	if (gblnOkay) {
		// swap the image
		document[strImageName].src = garrRollImages[strImageName][strAction].src;
	} //end if the browser supports this
	return true;
} //end function rollImage