/*-----------------------------------
Determines browser
-----------------------------------*/
function Is() {
    var agent = navigator.userAgent.toLowerCase();
    this.major = parseInt(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));
}

/*-----------------------------------
global variable initialization
-----------------------------------*/
var is = new Is();
var bWindow = null;
var swapArray = new Array();  //global that holds swap images info
var selectedImage = "";

/*-----------------------------------
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);
	//selectedImage = top.selectedImage;
	//onClickSwap(selectedImage);
}

/*-------Pop-up window for linecards---------*/
function popLine(URL, name) {
	if (bWindow && !bWindow.closed) {
			bWindow.location = URL;
			bWindow.focus();
		}else{	
  			bWindow = window.open(URL, name,"status=0,resizable,menubar=0,width=300,height=80");
		}
}

//================================================                  
//= Determines layer ID depending on the browser
//================================================
function getLayerRef(layerID) {
	if (is.NN) {
		return document.layers[layerID];
	} else {
		return document.all[layerID];
	}
}

//=================================================================================                  
//= Dynamically creates a pop-up window adjusting the dimensions of the images
//=================================================================================
function DynaWin(url, h, w, l, t, str) {
	poph = + h + 140
	popw = + w + 30
	disp = window.open("","pop","height=" + poph + ",width=" + popw + ",left=" + l + ",top=" + t + "" + str);
	content = '<HTML>';
	content += '<TITLE>Pop-up Window</TITLE>';
	content += '</HEAD>';
	content += '<BODY topmargin="10" leftmargin="0" marginheight="10" marginwidth="0" bgcolor="ffffff">';
	content += '<P ALIGN="center"><font size="+1" color="#005BAA" face="Verdana, sans sarif, Helvetica">' + str + '</font></P>';
	content += '<P ALIGN="CENTER"><img border="1" src="images/' + url + '" height="' + h + '" width="' + w + '"></P>';
	content += '<H3 ALIGN="CENTER"><A HREF="#" onClick="self.close()"><img src="../graphics/close_off.gif" width="98" height="42" alt="" border="0"></A></H3>';
	content += '</BODY></HTML>';
	disp.document.write(content);
	disp.document.close();
}

/*---------------------------------------
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;
			layerArray[layRef] = new Object();
			layerArray[layRef].layerRef = str.layers[layRef];
			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)[0]; // grab the extension
	var imgRef = imgObj.name;	 
	var divChar = srcString.lastIndexOf('/') + 1;    //finds the last '/' and records it's location
	var filePath = srcString.substring(0, divChar);
	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].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;
	}
}


function onClickSwap(imgName) {
	if(selectedImage != imgName) {
		swap(imgName, 'on');
		if(selectedImage != '') {
			swap(selectedImage, 'off');
		}
		selectedImage = imgName;
		return true;
	} else {
		swap(imgName, 'on');
		return false;
	}
}

// called from onMouseOver and onMouseOut
function mouseSwap(imgName, onoff) {
	if(selectedImage != imgName) {
		swap(imgName, onoff);
	}
}
