// DHTML layer handling


// create a DIV tag
function createLayer(name, left, top, width, height, visible, content, styleClass) {
	document.writeln('<div class="'+styleClass+'" id="' + name + '" style="position:absolute; OVERFLOW: hidden; left:' + left + 'px; top:' + top + 'px; width:' + width + 'px; height:' + height + 'px;' + ' visibility:' + (visible ? 'visible;' : 'hidden;') +  '">');
	document.writeln(content);
	document.writeln('</div>');
}

// get the DIV object called <name>
function getLayer(name) {
	var theObj = document.getElementById(name);
	if (theObj)
		return theObj.style;
	else
		return null;
}

// move DIV <name> to x,y; use <imageName> as reference postion 
function positionLayer(name, x, y, imageName) {	
  	var layer = getLayer(name);		
	if (layer != null) {
		var layerPositioner = document.getElementById(imageName);
   		layer.left = (x+getAbsX(layerPositioner)) + "px";
		layer.top  = (y+getAbsY(layerPositioner)) + "px";
	}
}

// make DIV invisible
function hideLayer(name) {		
  	var layer = getLayer(name);		
	if (layer != null) {
		 layer.visibility = "hidden";
	}
}

// make DIV visible
function showLayer(name) {		
  	var layer = getLayer(name);		
	if (layer != null) {
	 	layer.visibility = "visible";
	}
}

// clip DIV display to clipleft, cliptop, clipright, clipbottom
// used for panning
function clipLayer(name, clipleft, cliptop, clipright, clipbottom) {		
	var layer = getLayer(name);		
	if (layer != null)
		layer.clip = 'rect(' + cliptop + ' ' +  clipright + ' ' + clipbottom + ' ' + clipleft +')';
}

// clip DIV display to clipleft, cliptip, clipright, clipbottom
// used for zoom box
function clipBox(name, startX, startY, endX, endY, imageName) {		
	var layer = getLayer(name);		
	if (layer != null) {

		var width = endX - startX;
		var height = endY - startY;
		
		var layerPositioner = document.getElementById(imageName);
	
		if (width > 0)layer.left = (startX+getAbsX(layerPositioner)) + "px";
		else layer.left = (endX+getAbsX(layerPositioner)) + "px";
		if (height > 0) layer.top = (startY+getAbsY(layerPositioner)) + "px";
		else layer.top = (endY+getAbsY(layerPositioner)) + "px";
		// Set the width and height of the zoom box.
		layer.width = Math.abs(width) + "px";
		layer.height = Math.abs(height) + "px";
	}
}

// methods to find out where the positioner image starts in reference to the browser page
function getAbsX(elt) { 
	return (elt.x) ? elt.x : getAbsPos(elt,"Left"); 
}
function getAbsY(elt) { 
	return (elt.y) ? elt.y : getAbsPos(elt,"Top"); 
}
function getAbsPos(elt,which) {
	iPos = 0;
	while (elt != null) {
		iPos += elt["offset" + which];
		elt = elt.offsetParent;
	}
	return iPos;
}



//////////////////
/*-----------------------------------
global variable initialization
-----------------------------------*/
var swapArray = new Array();  //global that holds swap images info

//= Determines layer ID depending on the browser

function getLayerRef(layerID) {
	return document.getElementById(layerID);
}

/*-----------------------------------
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_nav && !is_nav6up) {
		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 fnameExp = /(\.|_on\.)[^\.]*$/;
	var ftypeExp = /\.[^\.]*$/;   // regular expression used to split the filename string
	var srcString = imgObj.src;
	var extString = srcString.match(ftypeExp); // grab the extension
	var fnameString = srcString.split(fnameExp, 1);
	var imgRef = imgObj.name;	 
	swapArray[imgRef] = new Object();
	swapArray[imgRef].off = new Image();
	swapArray[imgRef].off.src = fnameString + extString;
	swapArray[imgRef].on = new Image();
	swapArray[imgRef].on.src = fnameString + "_on" + extString;
	swapArray[imgRef].layerRef = imgObj;
}

/*---------------------------------------
Called from the <a href> tag      
Swap image function for rollovers 
---------------------------------------*/
function swap(imgName, onoff, whichButton) {

	if ((whichButton == imgName) && (swapArray[imgName] != null)) {
		if (onoff == 'on') {
			swapArray[imgName].layerRef.src = swapArray[imgName]['on'].src;
		} else {
			swapArray[imgName].layerRef.src = swapArray[imgName]['on'].src;
		}
	} else if (swapArray[imgName] != null) {
		swapArray[imgName].layerRef.src = swapArray[imgName][onoff].src;
	}
}

function swapGroup(imgName, group) {
	for (prop in swapArray) {
		if (prop.indexOf(group) != -1) {
			swap(prop, 'off');
		}
	}
	swap(imgName, 'on');
}

function launchWindow(URL, name, width, height) {
	if (document.all) {
		attr = "location=0,status=0,menubar=0,toolbar=0,resizable=1,scrollbars=1,width=" + width + ",height=" + height +",left=0,top=0";
	} else {
		attr = "location=0,status=0,menubar=0,toolbar=0,resizable=1,scrollbars=1,width=" + width + ",height=" + height +",screenX=0,screenY=0";
	}
	bWindow = window.open(URL, name,attr);
}