// Determines browser
function Is() {
   var agent = navigator.userAgent.toLowerCase();
   this.NN  = ((agent.indexOf('mozilla')!=-1) && ((agent.indexOf('spoofer')==-1) && (agent.indexOf('compatible') == -1)) && (parseFloat(navigator.appVersion)<5));
}

//global variable initialization
var is = new Is();

//global that holds swap images info
var swapArray = new Array();  

// Called from the onLoad() inside the body tag 
// Creates arrays for all images and references 
// to the layers involved in the navigation     
function initialize() {
	parseLayers(document);
}

// Called from initialize()
// Automatically parse every layer in document,
// determining which have swappable images
function parseLayers(str) {
	for (var i=0; i < str.images.length; i++) {
		if (str.images[i].name != "") {
			createImageObjects(str.images[i]);
		}
	}
	if (is.NN) {
		for (var i=0; i < str.layers.length; i++) {
			parseLayers(str.layers[i].document);
		}
	}
}

// Called from parseLayers()
// Preloads and creates object references for swappable images
// including _on state, _off state, and DOM image object path
function createImageObjects(imgObj) {
	var imgRef = imgObj.name;
	swapArray[imgRef] = new Object();
	swapArray[imgRef].on = new Image();
	swapArray[imgRef].on.src = "images/" + imgRef + "_on.gif";
	swapArray[imgRef].off = new Image();
	swapArray[imgRef].off.src = "images/" + imgRef + "_off.gif"; 
	swapArray[imgRef].layerRef = imgObj;
}

/*---------------------------------------
Called from the <a href> tag      
Swap image function for rollovers 
---------------------------------------*/
function swap(imgName, onoff) {
	if (swapArray[imgName] != null)
		swapArray[imgName].layerRef.src = swapArray[imgName][onoff].src;
}

/*---------------------------------------
Called from the <a href> tag      
Toggle images function for rollovers 
---------------------------------------*/
function toggle(imgName, onoff) {
	if (swapArray[imgName] != null) {
		for (imgRef in swapArray) {
			swapArray[imgRef].layerRef.src = swapArray[imgRef]['off'].src;
		}
		swapArray[imgName].layerRef.src = swapArray[imgName][onoff].src;
	}
}
