// menuDropdown.js - implements an dropdown menu based on a HTML list
// Author: Dave Lindquist (http://www.gazingus.org)
//----------------
var currentMenu = null;
var secs;
var timerID = null;
if (!document.getElementById) document.getElementById = function() { return null; }
//--------------------------------------------------------------------------------------
function StartTimer(Secs)
{
if (Secs>0) secs=Secs;
self.status = secs;
if (secs==0)
  {
  if (currentMenu) currentMenu.style.visibility = "hidden";
  clearTimeout(timerID);
  timerID = null;
  }
else
  {
  secs = secs - 1;
  if (timerID!=null) {clearTimeout(timerID);timerID = null;}
  if (timerID==null) timerID=self.setTimeout("StartTimer()", 1000);
  }
}
//--------------------------------------------------------------------------------------
function StopTimer()
{
if (timerID!=null)
  {
  clearTimeout(timerID);
  timerID = null;
  }
}
//--------------------------------------------------------------------------------------
function initializeMenu(menuId, actuatorId)
{
var menu = document.getElementById(menuId);
var actuator = document.getElementById(actuatorId);
timerID = null;
if (menu == null || actuator == null) return;
//----------------
actuator.onmouseover = function()
  {
  if (currentMenu)
    {
    currentMenu.style.visibility = "hidden";
    this.showMenu();
    }
  StopTimer();
  }
//----------------
menu.onmouseover = function()
  {
  StopTimer();
  }
//----------------
menu.onmouseout = function()
  {
  StartTimer(1);
  }
//----------------
actuator.onclick = function()
  {
  if (currentMenu == null)
    {
    this.showMenu();
    }
  else
    {
    currentMenu.style.visibility = "hidden";
    currentMenu = null;
    }
  return false;
  }
//----------------
actuator.showMenu = function()
  {
  menu.style.left = this.offsetLeft + "px";
  menu.style.top = this.offsetTop + this.offsetHeight + "px";
  menu.style.visibility = "visible";
  currentMenu = menu;
  }
//----------------
}
//--------------------------------------------------------------------------------------