// Just one global variable. Used to identify a setTimeout.
//Adding a second menu will call for the second timerId
// and second versions of the functions that use it.
//It's not elegant, but they're such tiny little scripts, 
//and the alternative makes my head hurt.
var timerId
var timerId2

//The following is Danny Goodman's code. 
//It returns a style object of a named element across browsers.
//One argument, the element's name. 
//Using this makes things a lot easier later.

function getObject(obj) {
   var theObj ;

   if (document.layers) {
      if (typeof obj == "string") {
         return document.layers[obj];
      } else {
         return obj;
      }
   }

   if (document.all && !document.getElementById) {
      if (typeof obj == "string") {
         return document.all(obj).style;
      } else {
         return obj.style;
      }
   }
   
   if (document.getElementById) {
      if (typeof obj == "string") {
         return document.getElementById(obj).style;
      } else {
         return obj.style;
      }
   }
   return null
}

// Sets the visibility of an object to visible
function show(obj) {
   var theObj = getObject(obj);
   theObj.visibility = "visible";
}

// Sets the visibility of an object to hidden
function hide(obj) {
   var theObj = getObject(obj);
   theObj.visibility = "hidden";
}


//This is the big function that is actually called in the page.
//Basically this function finds the object being moused over on the page and moves the layer containing the menu
//into the right spot. Without doing it dynamically it's basically hit or miss whether or not it will line up correctly.
//===================================================================================================
//USAGE
//"this" will be used for the 'obj' argument. 
//The 'lyr' [layer] will be the name of the CSS Layer which contains the secondary menu.
//That menu can be created in dreamweaver and placed basically anywhere on the page.
//Just set the visibility to 'hidden' and that's all there is to it.
//Trying to place it approximately where it goes on the page would be best.
//The menu should sit at the bottom of the image, so this script calculates that.
//This script isn't really portable, since it's really only designed to work on this specific page. 
//The goal is a minimum of head scratching for the non expert.

function setLayer(obj,lyr)	{
//This grabs the height of the image being moused over. The script is
//actually called from the <a> tag, so the first child is the <IMG>.
//like I said, not really portable, but it's one less thing for people
//to worry about when putting in a new menu on this specific page.
	
	var offset = obj.childNodes[0].height;
	var newX = findXPos(obj);
	var newY = findYPos(obj);
    var theObj = getObject(lyr);

//Firefox, for whatever reason, messes up the offset by about ten pixels, so I added this 
//"if" statement to see if I could clear it up. It seemed to work. It's purely cosmetic. 

	if (document.getElementById && !document.all) {
         offset -= 10;
		
		 }
	theObj.top = newY  + offset +'px';
	theObj.left = newX  +  'px';
}


//hides a "lyr" [layer] after a spcificed period of time
//"secs" (in milliseconds.)


function hideSlow(lyr,secs)	{
	timerId= eval("setTimeout('hide(\""+lyr+"\")',"+secs+")");
}

//same deal just a second incarnation of timerId...
function hideSlow2(lyr,secs)	{
	timerId2= eval("setTimeout('hide(\""+lyr+"\")',"+secs+")");
}
//makes sure there's no premature hiding of the layer.
//Needs to be called at every mouseover in the hidden menu to clear
//any onmouseout setTimeouts that have been started by the above function.

function keepUp()	{
	clearTimeout(timerId);
}

function keepUp2()	{
	clearTimeout(timerId2);
}

//These two functions find the current position of the called object on the page
//The while loop with the addition is designed to make up for the various
//and sundry ways that different browsers calculate the offsets.

function findXPos(obj)	{
	var currleft = 0;
	if (obj.offsetParent)	{
		while (obj.offsetParent)	{
			currleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}	else if (obj.x) {
		currleft += obj.x;
	}
	return currleft;
}

function findYPos(obj)	{
	var currtop = 0;
	if (obj.offsetParent)	{
		while (obj.offsetParent)	{
			currtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}	else if (obj.y) {
		currtop += obj.y;
		}
	return currtop;

}

