//
// FNI Menu (DHTML Menu System) - Version 1.2.0
//
// Copyright 2004 (c) First Net Impressions, LLC. All Rights Reserved.
// Visit http://www.firstnetimpressions.com/
//
// This is *NOT* free software.
//  
// Do not change the contents of this file.
//

function menuGlobalsObject()
{
  this.delay = 1000;
  this.zindex = 1;
  this.timer = 0;
  this.popupids = new Array();
  this.px = (document.childNodes) ? 'px' : 0;
}

function menuGetLeft(obj)
{
  var left = obj.offsetLeft;
  var parent = obj.offsetParent;
  while(parent != null)
  {
    left += parent.offsetLeft;
    parent = parent.offsetParent;
  }
  return left;
}

function menuGetTop(obj)
{
  var top = obj.offsetTop;
  var parent = obj.offsetParent;
  while(parent != null)
  {
    top += parent.offsetTop;
    parent = parent.offsetParent;
  }
  return top;
}

function menuGetParent(obj)
{
  var pid = '';
  var parent = obj.offsetParent;
  while(parent != null)
  {
    if(parent.className.substring(0, 7) == 'fnimenu')
    {
      pid = parent.id;
      break;
    }
    parent = parent.offsetParent;
  }
  return pid;
}

function menuStackGrow(cid)
{
  menuGlobals.popupids.push(cid);
}

function menuStackShrink(pid)
{
  while(menuGlobals.popupids.length > 0)
  {
    var popupid = menuGlobals.popupids.pop();
    if(popupid == pid)
    {
      menuGlobals.popupids.push(popupid);
      break;
    }
    var popup = document.getElementById(popupid);
    var style = (popup.style) ? popup.style : popup;
    style.visibility = 'hidden';
  }
}

function menuRaise()
{
  // Allow defaults for the function arguments

  var marker = (arguments.length > 0) ? arguments[0] : null;
  var cid = (arguments.length > 1) ? arguments[1] : '';
  var place = (arguments.length > 2) ? arguments[2] : '';
  var xoffset = (arguments.length > 3) ? arguments[3] : 0;
  var yoffset = (arguments.length > 4) ? arguments[4] : 0;

  // The marker must, at a minimum, be provided

  if(marker == null)
  {
    return;
  }

  // Cancel the timer set to lower all popup menus

  clearTimeout(menuGlobals.timer);

  // The marker must be contained within a parent menu

  var pid = menuGetParent(marker);

  if(pid == '')
  {
    return;
  }

  // Shrink the menu stack back so only the parent menu is visible

  menuStackShrink(pid);

  // No further action necessary when no popup child is provided

  if(cid == '')
  {
    return;
  }

  // Gather reference information for child and parent objects

  var parent = document.getElementById(pid);
  var pstyle = (parent.style) ? parent.style : parent;
  var child = document.getElementById(cid);
  var cstyle = (child.style) ? child.style : child;

  // Determine popup child menu placement using the marker for reference

  var xorigin = menuGetLeft(marker) + xoffset;
  var yorigin = menuGetTop(marker) + yoffset;

  if(place == 'top')
  {
    yorigin -= child.offsetHeight;
  }
  else if(place == 'left')
  {
    xorigin -= child.offsetWidth;
  }
  else if(place == 'right')
  {
    xorigin += marker.offsetWidth;
  }
  else if(place == 'bottom')
  {
    yorigin += marker.offsetHeight;
  }

  // Position the popup child (x, y, z) and make it visible

  cstyle.left = xorigin + menuGlobals.px;
  cstyle.top = yorigin + menuGlobals.px;
  cstyle.zIndex = pstyle.zIndex + menuGlobals.zindex + 1;
  cstyle.visibility = 'visible';

  // Grow the menu stack to include the popup child menu

  menuStackGrow(cid);
}

function menuLower()
{
  menuGlobals.timer = setTimeout('menuStackShrink(null)', menuGlobals.delay);
}

var menuGlobals = new menuGlobalsObject();