//imageSwap.js		
//

//
// Provides user feedback for navigation links by changing out the image when 
// the user places his or her mouse over it. Explicit creation of image 
// objects is not required, as it is in many similar scripts, making this 
// script more portable between pages and applications.
//
// author Jaeson Paul
// version 1.0
// last edited 20020606
// tested successfully in NS4.7, NS6, IE6 on Windows 2000 Pro
//

// CONVENTIONS: 
// 1) Image tags included in swap functions must have name attribute set to
//    'nav_'*, where '*' is unique in the document.
// 2) The filename for each graphic's over state must be 
//    [basefilename]'-over'[.ext], and the files must live in the same 
//    folder.
// 

// renamed swapImage.js by tack@tractionco.com to aid command line tab
// completion when an 'images' folder is present in the same directory

// GLOBAL DECLARATIONS
var navButtons = new Array(); // Array of navButton objects, read from the
// document by buildNavButtons
var navButtonsBuilt = false;  // Boolean value to indicate whether the array
// has been built

// OBJECT CONSTRUCTORS
function navButton(){ 
// constructor object for the navButton object, which stores all properties 
// and methods for the mouseover links.
	this.over=new Image();
	this.base=new Image();
	this.name="";
	return this;
}

// FUNCTIONS
function buildNavButtons(){
// builds the navButtons array by reading the HTML parameters from the doc.
var currImg;
	if (document.images){
		for (i=0; i<document.images.length; i++) {
			currImg = document.images[i];	
			if (currImg.name.indexOf("nav_")!=-1){
				navButtons[currImg.name] = new navButton();
				navButtons[currImg.name].base.src = currImg.src;
				// begin part that adds "-over"
				if(currImg.name.indexOf("-down") == -1){	// don't create over states for down state images
					navButtons[currImg.name].over.src 
						= currImg.src.substring(0, currImg.src.length-4) 
						+ "-over" 
						+ currImg.src.substring(currImg.src.length-4);
				}
				// end part that adds "-over"
				navButtons[currImg.name].name = currImg.name;
			}
		}
	}	
	navButtonsBuilt = true;
}

/* the following 3 have been modified by tack@tractionco.com for Traction Corporation: www.tractionco.com
 * The isUp() function has been added and integrated into nav*() so that we can follow the same
 * image naming convention (-down) for downstate images and not have to do any extra
 * work to make the rollover script not swap them out.
 */

function navOver(imgName){
// handles the mouseover event for a navbutton. Set imgName to the NAME 
// attribute of the IMG tag when calling.
	if (navButtonsBuilt && isUp(imgName)) {
		var cmdStr = "document.images['" + imgName + "'].src" +" = navButtons['" + imgName + "'].over.src";
		eval(cmdStr);
	}
}

function navOff(imgName){
// handles the mouseout event for a navbutton. Set imgName to the NAME 
// attribute of the IMG tag when calling.
	if (navButtonsBuilt && isUp(imgName)) {
		var cmdStr = "document.images['" + imgName + "'].src" +" = navButtons['" + imgName + "'].base.src";
		eval(cmdStr);
	}
}

function isUp(imgName){
// checks the given image for downstate.  This is called from nav*() so is assumed that not downstate = upstate
// returns true for upstate, false for downstate
	returnState = "";
	if(eval("document.images['" + imgName + "'].src").indexOf("-down") == -1){
		returnState = true;
	}else{
		returnState = false;
	}
	
	return returnState;	
}