//
// menu.js 
//

var inmenu    = false;
var lastwhich = 0;
var lastmenu  = 0;
var lastwidth = 0;

var leftMnMenuDfltColor  = "#ffffff";
var leftMnMenuDfltWeight = "bold";
var leftMnMenuRollColor  = "#ffed55";
var leftMnMenuRollWeight = "bold";
var leftSbMenuDfltColor  = "#000000";
var leftSbMenuDfltWeight = "normal";
var leftSbMenuRollColor  = "#a1040f";
var leftSbMenuRollWeight = "bold";
var leftXOffset          = 120;
var leftYOffset          = 8;

var topMnMenuDfltColor   = "#ffffff";
var topMnMenuDfltWeight  = "bold";
var topMnMenuRollColor   = "#ffed55";
var topMnMenuRollWeight  = "bold";
var topSbMenuDfltColor   = "#000000";
var topSbMenuDfltWeight  = "normal";
var topSbMenuRollColor   = "#a1040f";
var topSbMenuRollWeight  = "bold";
var topXOffset           = -4;
var topYOffset           = 25;

//
// highlight menu option (and display drop down menu on rollover if applicable)
//
function Menu(which,menuId,descr,width,hcolor,hweight) {
   inmenu    = true;
   oldwhich  = lastwhich;
   oldmenu   = lastmenu;
   oldwidth  = lastwidth;
   lastwhich = which;
   lastmenu  = menuId;
   lastwidth = width;

   mr    = GetObject("mrow-"  + menuId);
   mlink = GetStyleObject("mlink-" + menuId);
   mbutton = menuId + "-button";  
   window.status = descr;

   RollColor  = eval(which + "MnMenuRollColor");
   RollWeight = eval(which + "MnMenuRollWeight");
   XOffset    = eval(which + "XOffset");
   YOffset    = eval(which + "YOffset");

   if (hcolor==null)  mlink.color      = RollColor;  else mlink.color = hcolor;
   if (hweight==null) mlink.fontWeight = RollWeight; else mlink.fontWeight=hweight;
   if (which=='left') document.images[mbutton].src = "http://www.pbaa.net/pbaa/graphics/menubuttonon.gif";

   if (width != 0) {
      if (oldmenu && oldwhich=='left') Erase(oldwhich,oldmenu,oldwidth);
      box            = GetStyleObject("box-" + menuId);
      trueX          = GetRealLeft(mr);
      trueY          = GetRealTop(mr);
      box.left       = trueX + XOffset;
      box.top        = trueY + YOffset;
      box.visibility = "visible";
      box.width      = width + "px";
   }   
}

//
// unhighlight menu option (and hide drop down menu on mouseout if applicable)
//
function Erase(which,menuId,width,ucolor,uweight) {

   if (inmenu && lastmenu == menuId) return;
   mlink               = GetStyleObject("mlink-" + menuId);
   mbutton = menuId + "-button";  
   window.status = "";

   DfltColor  = eval(which + "MnMenuDfltColor");
   DfltWeight = eval(which + "MnMenuDfltWeight");

  
   if (ucolor==null)  mlink.color      = DfltColor;  else mlink.color = ucolor;
   if (uweight==null) mlink.fontWeight = DfltWeight; else mlink.fontWeight = uweight;
   if (which=='left') document.images[mbutton].src = "http://www.pbaa.net/pbaa/graphics/menubutton.gif";

   if (width != 0) {
       box             = GetStyleObject("box-" + menuId);
       box.visibility  = "hidden";
   }   
}                 

//
// delay calling Erase function to determine if still looking at this menu
//
function Timeout(which,menuId,width) {

   inmenu = false;
   if (width==0) delay = 0; else delay = 1500;
   window.setTimeout("Erase('" + which + "', menuId='" + menuId  + "', width='" + width +"');",delay);
}

//
// highlight a submenu item on rollover
//
function MHighlight(which,menuId,itemId,descr,hcolor,hweight) {

   inmenu   = true;
   lastmenu = menuId;
   lastwhich = which;
   ilink    = GetStyleObject(itemId);
   window.status = descr;

   RollColor  = eval(which + "SbMenuRollColor");
   RollWeight = eval(which + "SbMenuRollWeight");

   if (hcolor==null)  ilink.color      = RollColor;  else ilink.color = hcolor;
   if (hweight==null) ilink.fontWeight = RollWeight; else ilink.fontWeight=hweight;
}

//
// unhighlight a submenu item on mouseout
//
function MUnhighlight(which,menuId,itemId,ucolor,uweight) {

   Timeout(which,menuId,'999',ucolor,uweight);
   ilink = GetStyleObject(itemId);

   DfltColor  = eval(which + "SbMenuDfltColor");
   DfltWeight = eval(which + "SbMenuDfltWeight");

   if (ucolor==null)  ilink.color      = DfltColor;  else ilink.color = ucolor;
   if (uweight==null) ilink.fontWeight = DfltWeight; else ilink.fontWeight=uweight;
}

//
// obtain the desired object in different browser models
//
function GetObject(id) {
   if (document.getElementById) return document.getElementById(id);
   else if (document.layers)    return document.layers[id];
   else if (document.all)       return document.all[id];
   else { alert("DHTML support not found.");
          return false;}
}

//
// obtain the desired syle element in different browser models
//
function GetStyleObject(id) {
   if (document.getElementById) return document.getElementById(id).style;
   else if (document.layers)    return document.layers[id];
   else if (document.all)       return document.all[id].style;
   else { alert("DHTML support not found.");
          return false;}
}

//
// obtain the left offset of an element
//
function GetRealLeft(el) {
    xPos = el.offsetLeft;
    tempEl = el.offsetParent;
    while (tempEl != null) {
        xPos += tempEl.offsetLeft;
        tempEl = tempEl.offsetParent;
    }
    return xPos;
}

//
// obtain the top offset of an element
//
function GetRealTop(el) {
    yPos = el.offsetTop;
    tempEl = el.offsetParent;
    while (tempEl != null) {
        yPos += tempEl.offsetTop;
        tempEl = tempEl.offsetParent;
    }
    return yPos;
}
   