var inmenu=false;
var lastmenu=0;
var lastwidth=0;

// function DBMenuRight called when onMouseOver event occurs //

function DBMenuRight(current,menu_width) 
{
   if (!document.getElementById) return;
   inmenu=true;
   oldmenu=lastmenu;
   lastmenu=current;

   oldwidth=lastwidth; 
   lastwidth=menu_width;
   if (oldmenu) Erase(oldmenu,oldwidth);

   primaryMenuEl=document.getElementById("lvl1_" + current);  // Set var to Primary menu option ID
   primaryMenuEl.style.cursor="pointer";
   primaryMenuEl.style.backgroundColor="#ffffff";

   if (menu_width != "0")   // level 2 menu required 
   {
      level2MenuEl=document.getElementById(current);          // Set var to secondary menu options ID

      // calculate Left and top offsets for displaying the level 2 menu options
      // (Add all parent elements left offsets and top offsets)
      totalLeft = 0;
      totalTop  = 0;
      parentElement = primaryMenuEl.offsetParent;
      while (parentElement != null)
      {
        l = parentElement.offsetLeft;
        t = parentElement.offsetTop;
        //  w = parentElement.offsetWidth;
        //  h = parentElement.offsetHeight;
        totalLeft = totalLeft + l;
        totalTop  = totalTop  + t;      
        parentElement = parentElement.offsetParent;
      }
 
      leftPos = totalLeft + primaryMenuEl.offsetWidth - 3;
      topPos  = totalTop  + primaryMenuEl.offsetTop + 2;

    // If level 2 menu height is greater than visible window height, start menu at top of window
    // if level2 menu goes beyond bottom of window, move menu up.


      level2MenuHeight = level2MenuEl.offsetHeight;    // Get level2 menu height

    // Get visible window height - browser specific

      d = document;

      if (typeof(window.innerWidth) == 'number' )                  // non IE 
      {
         visibleWindowHeight = window.innerHeight;
      }
      else
      {
         if (d.documentElement && d.documentElement.clientHeight)  // IE 6+ in 'standards compliant mode'
         {
            visibleWindowHeight = d.documentElement.clientHeight;
         }
         else
         {
            if (d.body && d.body.clientHeight)                      // IE 4 compatible
            {
               visibleWindowHeight = d.body.clientHeight;
            }
         }
      }  

    // Get visible window top - browser specific

      visibleWindowTop = 0;

      if (typeof(window.pageYOffset) == 'number')                   // Non IE
      {
        visibleWindowTop = window.pageYOffset;
      }
      else
      {
         if (d.body && d.body.scrollTop)                            //DOM compliant
         {
            visibleWindowTop = d.body.scrollTop;
         }
         else
         {
            if (d.documentElement && d.documentElement.scrollTop)    // IE 6+ in 'standards compliant mode'
            {
               visibleWindowTop = d.documentElement.scrollTop;
            }
         }
      }

    // determine whether menu height is greater than window height

      if (visibleWindowHeight < level2MenuHeight)
      {
        topPos = visibleWindowTop;  // start menu at top of window
      }

    // determine whether menu extends beyond the bottom of the window 

      else
      {
        if (topPos + level2MenuHeight - visibleWindowTop > visibleWindowHeight)
        {
          topPos = visibleWindowHeight - level2MenuHeight + visibleWindowTop;   // move menu up so that it sits on bottom edge of window 
        }
      }

      // document.write("l = "+l+"<br />");
      // document.write("t = "+t+"<br />");
      // document.write("w = "+w+"<br />");
      // document.write("h = "+h+"<br />");
      // document.write("Left = "+leftPos+"<br />");
      // document.write("Top = "+topPos+"<br />");

      level2MenuEl.style.left= leftPos +"px";
      level2MenuEl.style.top = topPos  +"px";
      level2MenuEl.style.visibility="visible";
      level2MenuEl.style.backgroundColor="#e1e1e1";
      level2MenuEl.style.width=menu_width;
      level2MenuEl.style.cursor="pointer";
   }  // end if not 'nomenu'

}

function Erase(current,menu_width) 
{
   if (!document.getElementById) return;
   if (inmenu && lastmenu==current) 
   {
	  return;
   }
   primaryMenuEl=document.getElementById("lvl1_" + current);
   primaryMenuEl.style.backgroundColor="#e1e1e1";
   if (menu_width != "0")  
   {
      level2MenuEl=document.getElementById(current);
      level2MenuEl.style.visibility="hidden";
   }
}

function Timeout(current,menu_width) 
{
   inmenu=false;
   window.setTimeout("Erase('" + current + "','" + menu_width + "');",200);
}

function Highlight(menu,item) 
{
   if (!document.getElementById) return;
   inmenu=true;
   lastmenu=menu;
   obj=document.getElementById(item);
   obj.style.backgroundColor="#ccffff";
}

function UnHighlight(menu,item) 
{
   if (!document.getElementById) return;
   Timeout(menu);
   obj=document.getElementById(item);
   obj.style.backgroundColor="#e1e1e1";
}

