var PreviousImage;

function showitem(intNum, blnShow) {
  var obj;
  var strName;
  strName = "menu" + intNum;
  // If getElementById is defined, let's use it. Works in IE5, NS6, and others.
  if (document.getElementById) {
    obj = document.getElementById(strName);
    if (obj)  // If it ain't defined, die quietly.
	    obj.style.visibility = blnShow ? "visible" : "hidden";
    return;
  }
  // for NS4 and variants
  if (document.layers) {
    obj = document.layers[strName];
    if (obj)  // If it's absent, die quietly.
	obj.visibility = blnShow ? "show" : "hide";
    return;
  }
  // For IE4
  if (document.all) {
    obj = document.all[strName];
    if (obj) // As before.
    	obj.style.visibility = blnShow ? "visible" : "hidden";
    return;
  }
}

/**
  * Shows only 1 menu, hides the others
  */

function showonlymenu(intNum)
{
  var i;
  for (i=1; i<=5; i++) {
    if (i == intNum) 
	showitem(i,true);
    else
	showitem(i,false);
  }
}

/**
  * This does 2 things - it highlights the image (using DOM0 API) and 
  * Will also show the menu associated with the button
  * blnShow == true iff the mouse is going over a given button
  */
  
function popMenu(intNum, strName, blnShow) {
  if (blnShow) {
	  showonlymenu(intNum,blnShow);

	  // Turn off old image
		if (PreviousImage!=''){
			highlightImage(PreviousImage, false);
		}
  }
  // The mouse-over image highlights
  highlightImage(strName, blnShow);
  PreviousImage=strName;
}

/**
  * Hack - in NS4, document.images doesn't find images inside a DIV, which
  * are considered to be in a separate layer.
  * This works around this hopefully.
  */
function highlightImage(strName, blnOn) {
  var objImg;
  objImg = document.images[strName];
  if (! objImg) {
    if (document.layers) {
	  objImg = document.layers["menuhead"].document.images[strName];
	} 
  }
  if (! objImg) {
	return; // Abandon all hope!
  }
  
  if (blnOn) {
    objImg.src = "images/nav/on_" + strName + ".gif";
  } else {
    objImg.src = "images/nav/" + strName + ".gif";
  }
}

/*** Dynamic HTML menu generation (run-time) */
/* USes document.write */

var arrSections = new Array();
function loadUpJs() {
  /* Now a no-op */
}

/**
  * Constructor for the Section class
  * params: internal (JS) id, name, target document id
  */

function Section(id, name, targetId) {
  this.id = id;
  this.name = name;
  this.targetId = targetId;
  this.children = new Array();
}

/** Inline script to write the products menu */

function createProductsMenu(objThing) {
  setupSections();
  var objDoc = objThing.document;
  objDoc.write("<tr>");
  var i;
  var objSection;
  objSection = findProductSection();
  for (i=0; i<objSection.children.length; i++) {
    if (i%4 == 0) {
        if (i>0) { // Put in a spacer cell
		objDoc.write("<td width='20'></td>");
	}
	objDoc.write("<td nowrap valign='top' align='left'>");
    }
    var objCat;
    objCat = arrSections[objSection.children[i]];
    objDoc.write("<a href=\"" + objCat.targetId + ".html\" class=\"amenu\">");
    objDoc.write(objCat.name);
    objDoc.write("</a>");
    if (i%4 == 3) {
	objDoc.write("</td>");
    } else { 
        objDoc.write("<br />");
    }
  }
  objDoc.write("</tr>");
}
    
/* Returns the section object. If it fails just does the top. */
function findProductSection()
{
  var i;
  for (i=0; i<arrSections.length; i++) {
   if (arrSections[i].targetId == 1103) {
     // Found it!
     return arrSections[i];
   }
  }
  return arrSections[1];
}

function getThing(strName) {
  if (document.getElementById)
	return document.getElementById(strName);
  if (document.all)
	return document.all[strName];
  if (document.layers)
  {
	var obj;
 	obj = document.layers[strName];
	if (! obj)
		obj = document.anchors[strName];
	if (! obj)
		obj = document.images[strName];
	return obj;
  }
}

// Try lots of different methods to try and determine an element's height
// Works best with a layer (absolute div)
function getElementHeight(obj)
{
  if (obj.height) return obj.height;
  if (obj.style) 
	if (obj.style.height) return obj.style.height;
  if (obj.clip)
	return obj.clip.height;
  if (obj.offsetHeight)
	return obj.offsetHeight;
  return 0;
}

function findPosY(obj)
{
	var curtop = 0;
	if (document.getElementById || document.all)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else 
	{
		if (obj.pageY) return obj.pageY;
		return obj.y; // Last resort
	}
	return curtop;
}
function findPosX(obj)
{
	var curleft = 0;
	if (document.getElementById || document.all)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else 
	{
		if (obj.pageX) return obj.pageX;
		return obj.x; // Last resort
	}
	return curleft;
}
function moveTo(obj,x,y) {
  if (obj.style)
  {
	obj.style.left = x;
	obj.style.top = y;
  	return;
  }
  if (obj.moveToAbsolute) {
	obj.moveToAbsolute(x,y);
  }
}

// Line up the bottom of objElem1 with the top of objElem2
function lineupElement(strElem1, strElem2)
{
  var objElem1 = getThing(strElem1);
  var objElem2 = getThing(strElem2);
  if (! (objElem1 && objElem2)) return; // Mask JS errors if it all goes wrong
  var intHt = getElementHeight(objElem1);
  var oldx = findPosX(objElem1);
  var intTargetY = findPosY(objElem2);
  if ((oldx == 0) || (newy ==0) || (intHt == 0)) {  // Work around for bug or sillyness
	return;
  }
  var newy = intTargetY - intHt;
  moveTo(objElem1,oldx,newy);
}

function positionMenus() {
  lineupElement("menu1","header-1px-line");
  lineupElement("menu4","header-1px-line");
}

