// Rollover Menu code, for Aberdare's Website
// By Greg Kempe (jasper@kempe.net)
// Feb 8 2002
// Use to your heart's content...
//
// Works for NS6, Opera 6, IE4+ (Win), IE5 (Mac)
// No direct testing for browsers is done, instead document.all and document.getElementById are used
// this results in disabling on crappier browsers

var timeoutRefs = new Array();  // array of timeout references, one for each menu
var clippings = new Array();
var bMenuInit = false;
var iHideDelay = 100;   // wait for how long before hiding?

var bUseScroll = false; // use scrolling? but messed right now...
var iScrollJump = 20;
var iScrollTimer = 5;   // how long before doing the next scroll movement?
var bUseFilters = true; // should MSIE/Win use filters?

function initMenu(item, menuID) {
  var oDiv = document.getElementById(menuID);
  var oParent, x, y;

  // get the x,y position by walking the offsetParent list
  x = item.offsetLeft;
  y = item.offsetTop + item.offsetHeight;

  oParent = item.offsetParent;
  while (oParent && oParent.tagName.toUpperCase() != 'BODY') {
    x += oParent.offsetLeft;
    y += oParent.offsetTop;
    oParent = oParent.offsetParent;
  }

  oDiv.style.left = x + 'px';
  oDiv.style.top = y + 'px';
  
  timeoutRefs[menuID] = null;
}

function doShowMenu(menuID, callingItem) {
  // init and show the menu
  var oMenu = document.getElementById(menuID);

  initMenu(callingItem, menuID);
  clearTimeout(timeoutRefs[menuID]);

  if (oMenu.style.visibility != 'visible') {
    clippings[menuID] = 0;

    // use filters?
    if (oMenu.filters && oMenu.filters[0] && bUseFilters) {
      oMenu.filters[0].apply();
      oMenu.style.visibility = 'visible';
      oMenu.filters[0].play();
    } else {
      oMenu.style.visibility = 'visible';
      scrollInMenu(menuID);
    }
  }
}

function scrollInMenu(menuID) {
  // scroll the menu in nicely
  var oMenu = document.getElementById(menuID);

  if (bUseScroll) {
    clippings[menuID] += iScrollJump;
    oMenu.style.clip = 'rect(auto auto ' + clippings[menuID] + 'px auto)';
  }

  if (bUseScroll && clippings[menuID] <= oMenu.offsetHeight) {
    setTimeout('scrollInMenu("' + menuID + '")', iScrollTimer);
  } else {
    oMenu.style.clip = 'rect(auto auto auto auto)';
  }
}

function hideMenu(menuID) {
  // hide the menu
  var oMenu = document.getElementById(menuID);
  clippings[menuID] = oMenu.offsetHeight;

  // use filters?
  if (oMenu.filters && oMenu.filters[0] && bUseFilters) {
    oMenu.style.clip = 'rect(auto auto auto auto)';
    oMenu.filters[0].apply();
    oMenu.style.visibility = 'hidden';
    oMenu.filters[0].play();
  } else scrollOutMenu(menuID);
}

function scrollOutMenu(menuID) {
  // scroll out the menu
  var oMenu = document.getElementById(menuID);
  
  if (bUseScroll) {
    clippings[menuID] -= iScrollJump;
    oMenu.style.clip = 'rect(auto auto ' + clippings[menuID] + 'px auto)';
  }
    
  if (bUseScroll && clippings[menuID] > 0) {
    setTimeout('scrollOutMenu("' + menuID + '")', iScrollTimer);
  } else {
    oMenu.style.visibility = 'hidden';
  }
}

function doMenuMove(menuID) {
  // clear the timeout if it is happening
  clearTimeout(timeoutRefs[menuID]);
}

function doMenuOut(menuID) {
  // set the timeout to clear the menu
  timeoutRefs[menuID] = setTimeout('hideMenu("' + menuID + '")', iHideDelay);
}
