<!--
/*
FileName	:	dhtmllayer.js
Description	:	Include file for cross-browser DHTML layer functions

REVISION HISTORY
1/14/2003		Chris Long - adapted this from code found on the net
									 and included a few of my own functions
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

**PLEASE NOTE**:  /jscript/browsercheck.js must be included with this file.
The browser checking file is necessary for the image location functions to work.
*/


/* returns a layer object which serves as a handle to that layer
 * 
 * @param layername 	 The number to translate. (Required)
 * @return Returns a layer object. 
 * @author Chris Long (radynski@yahoo.com) 
 * @version 1, January 14, 2003 
*/
function getLayerHandle(layername) {
	if(layername == "") return null;
	if(document.getElementById)
		return eval("document.getElementById('"+layername+"')");
	else if(document.all)
		return eval("document.all."+layername);
	else if(document.layers)
		return eval("document.layers['"+layername+"']");
	else
		return null;
}

// position the layer
function positionLayer(layer, x, y) {
	if (document.getElementById || document.all) {
		layer.style.left = x+"px";
		layer.style.top  = y+"px";
	}
	else if (document.layers) {
		layer.left = x;
		layer.top  = y;
	}
}

// layer visibility
function layerVisibility(layer, value) {
	if (document.getElementById || document.all) {
		layer.style.visibility = value;
	}
	else if (document.layers) {
		if (value == "visible") {
			layer.visibility = "show";
		}
		else {
			layer.visibility = "hide";
		}
	}
}

/* attaches a layer to an image location
 * best use: have a 1px transparent gif hold a location for you on a page
 *				 and have this function position the layer there
 * xdiff and ydiff are optional.  If you wish only to use ydiff only you must
 * call the function like attachLayerToImage(layername, image.gif, null, 5)
 *
 * @return (nothing)
 * @author Chris Long (radynski@yahoo.com) 
 * @version 1, January 14, 2003 
*/
function attachLayerToImage(layer, image, xdiff, ydiff) {
	var imagex = getImagePageLeft(image);
	var imagey = getImagePageTop(image);
	
	// adjust image to line up as specified
	if(xdiff) imagex += xdiff;
	if(ydiff) imagey += ydiff;
	
	positionLayer(layer, imagex, imagey);
}

// function to locate x coordinate of an image
function getImagePageLeft(img){
	var x, obj;

	if (document.all || document.getElementById){
		x = 0;
		obj = img;
		while (obj.offsetParent != null){
			x += obj.offsetLeft;
			obj = obj.offsetParent;
		}
		x += obj.offsetLeft;
		// account for inaccurate coordinates on IE for Macs
		if (is.b == "ie" && is.mac && is.v >= 5 && is.v < 6){
			x += 10;
		}
		return x;
	}
	else if (document.layers){
		if (img.container != null){
			return img.container.pageX + img.x;
		}
		else{
			return img.x;
		}
	}
	return -1;
}

// function to locate y coordinate of an image
function getImagePageTop(img){
	var y, obj;

	if (document.all || document.getElementById){
		y = 0;
		obj = img;
		while (obj.offsetParent != null){
			y += obj.offsetTop;
			obj = obj.offsetParent;
		}
		y += obj.offsetTop;
		// account for inaccurate coordinates on IE for Macs
		if (is.b == "ie" && is.mac && is.v >= 5 && is.v < 6){
			y += 15;
		}
		// account for inaccurate coordinates on Opera 7
		if (is.b == "op"){ y += 8; }
		return y;
	}
	else if (document.layers){
		if (img.container != null){
			return img.container.pageY + img.y;
		}
		else{
			return img.y;
		}
	}
	return -1;
}
//-->

