/********************************************************************************\
FileName    :	dropdown.js
Description :	.js include for cross-browser DHTML layer manipulation
Author      :	Chris Long (radynski@yahoo.com) rewritten and partially
					 adapted from code found at brainjar.com

++PLEASE NOTE++ :  browsercheck.js must be included with this file.
The browser checking file is necessary for the image location functions to work.
*********************************************************************************/


//this function  creates the dropping effect
function DropMenu(menuname) {
	var layerH = getLayerHandle(menuname+"DIV");
	if(layerH) {
		attachLayerToImage(layerH, menuname+"IMG", 150, 0);
		layerVisibility(layerH, "visible");
	}
}

//this function makes the current menu dissapear when you leave it's bounds.
function UpMenu(menuname) {
	var layerH = getLayerHandle(menuname+"DIV");
	if(layerH) layerVisibility(layerH, "hidden");
}


/* returns a layer object which serves as a handle to that layer
 * 
 * @param layername 	 The number to translate. (Required)
 * @return Returns a layer object. 
 * @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
		return null;
}

// position the layer
function positionLayer(layer, x, y) {
	if (document.getElementById || document.all) {
		if (isNaN(layer.style.top)) {
			layer.style.left = x+"px";
			layer.style.top  = y+"px";
		}
		else {
			layer.style.left = x;
			layer.style.top  = y;
		}
	}
}

// layer visibility
function layerVisibility(layer, value) {
	if (document.getElementById || document.all) {
		layer.style.visibility = value;
	}
}

/* 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)
 * @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 = 0;
	var obj = eval("document."+img);

	if (document.all || document.getElementById){
		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;
	}
	return -1;
}

// function to locate y coordinate of an image
function getImagePageTop(img){
	var y = 0;
	var obj = eval("document."+img);

	if (document.all || document.getElementById){
		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;
	}
	return -1;
}
