/*-----------------------------------
Determines browser
-----------------------------------*/
function Is() {
    var agent = navigator.userAgent.toLowerCase();
	this.major = parseInt(navigator.appVersion);
	this.minor = parseFloat(navigator.appVersion);
    this.NN  = ((agent.indexOf('mozilla')!=-1) && ((agent.indexOf('spoofer')==-1) && (agent.indexOf('compatible') == -1)));
    this.IE   = (agent.indexOf("msie") != -1);
    this.WIN = (agent.indexOf("win") != -1);
    this.IE5 = (this.IE && (agent.indexOf('5') != -1));
	this.NN6 = (this.NN && (this.major>= 5));
}

/*-----------------------------------
global variable initialization
-----------------------------------*/
var is = new Is();
/*-------if (is.NN) {
	if (is.minor <= 4.05) {
		self.location="../sorry.html"; //relocates anyone with < version 4.05 NS browser
	}
} else {
	if (is.major < 4) {
		self.location="../sorry.html"; //relocates anyone with < version 4 IE browser
	}
}---*/
var swapArray = new Array();  //global that holds swap images info
var whichButton = null;

/*-----------------------------------
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, 
and (NS only) create references to every 
layer in the document
---------------------------------------*/
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++) {
		    var layRef = str.layers[i].name;
			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 ftypeExp = /\.[^\.]*$/;   // regular expression used to split the filename string
	var srcString = imgObj.src;
	var extString = srcString.match(ftypeExp); // grab the extension
	var imgRef = imgObj.name;	 
	var divChar = srcString.lastIndexOf('/') + 1;    //finds the last '/' and records it's location
	var filePath = srcString.substring(divChar, 0);
	swapArray[imgRef] = new Object();
	swapArray[imgRef].on = new Image();
	swapArray[imgRef].on.src = filePath + imgRef + "_on" + extString;
	swapArray[imgRef].off = new Image();
	swapArray[imgRef].off.src = filePath + imgRef + "_off" + extString;
	swapArray[imgRef].press = new Image();
	swapArray[imgRef].press.src = filePath + imgRef + "_press" + extString;
	swapArray[imgRef].layerRef = imgObj;
}

/*---------------------------------------
Called from the <a href> tag      
Swap image function for rollovers 
---------------------------------------*/
function swap(imgName, onoff) {
	if ((whichButton == imgName) && (swapArray[imgName] != null)) {
		if (onoff == 'on') {
			swapArray[imgName].layerRef.src = swapArray[imgName][onoff].src;
		} else {
			swapArray[imgName].layerRef.src = swapArray[imgName]['on'].src;
		}
	} else if (swapArray[imgName] != null) {
		swapArray[imgName].layerRef.src = swapArray[imgName][onoff].src;
	}
}

function goButton(contentURL, imgName) {
	if ((whichButton != null) && (swapArray[whichButton] != null)) {
		swapArray[whichButton].layerRef.src = swapArray[whichButton]['off'].src;
	}
	swap(imgName, 'on');
	parent.content.location.href = contentURL;
	whichButton = imgName;
}