//

// FNI Menu (DHTML Menu System) - Version 1.4.2

//

// 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.

//

// 1.3.0 mouse-over effect now sticks on menu tree

// 1.4.0 GetLeft and GetTop now end sum when relative container is found

// 1.4.1 using substring() instead of substr() consistently

// 1.4.2 correction to method used in GetLeft and GetTop to identify relative containers

//



function menuGlobalsObject()

{

  this.delay = 300;

  this.zindex = 1;

  this.timer = 0;

  this.popups = new Array();

  this.ahrefs = new Array();

  this.px = (document.childNodes) ? 'px' : 0;

}



function menuGetPositionStyle(obj)

{

  return (obj.currentStyle) ? obj.currentStyle['position'] : getComputedStyle(obj, null).getPropertyValue('position');

}



function menuGetLeft(obj)

{

  var left = obj.offsetLeft;

  var parent = obj.offsetParent;

  while(parent != null)

  {

    left += parent.offsetLeft;

    if(menuGetPositionStyle(parent).indexOf('relative') > -1)

    {

      break;

    }

    parent = parent.offsetParent;

  }

  return left;

}



function menuGetTop(obj)

{

  var top = obj.offsetTop;

  var parent = obj.offsetParent;

  while(parent != null)

  {

    top += parent.offsetTop;

    if(menuGetPositionStyle(parent).indexOf('relative') > -1)

    {

      break;

    }

    parent = parent.offsetParent;

  }

  return top;

}



function menuGetParentID(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(ahref, popup)

{

  menuGlobals.popups.push(popup);

  menuGlobals.ahrefs.push(ahref);



  var names = ahref.className.split(" ");

  var hover = (names.length > 1) ? " " + names[names.length - 1] + "-hover" : "";

  ahref.className += hover;

}



function menuStackShrink(pid)

{

  while(menuGlobals.popups.length > 0)

  {

    var popup = menuGlobals.popups.pop();



    if(popup.id == pid)

    {

      menuGlobals.popups.push(popup);

      break;

    }



    var style = (popup.style) ? popup.style : popup;

    style.visibility = 'hidden';



    var ahref = menuGlobals.ahrefs.pop();

    var names = ahref.className.split(" ");

    var hover = (names.length > 2) ? " " + names[names.length - 2] + "-hover" : "";

    ahref.className = ahref.className.substring(0, ahref.className.length - hover.length);

  }

}



function menuRaise()

{

  // Allow defaults for the function arguments



  var ahref = (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 href must, at a minimum, be provided



  if(ahref == null)

  {

    return;

  }



  // Cancel the timer set to lower all popup menus



  clearTimeout(menuGlobals.timer);



  // The href must be contained within a parent menu



  var pid = menuGetParentID(ahref);



  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 href for reference



  var xorigin = menuGetLeft(ahref) + xoffset;

  var yorigin = menuGetTop(ahref) + yoffset;



  if(place == 'top')

  {

    yorigin -= child.offsetHeight;

  }

  else if(place == 'left')

  {

    xorigin -= child.offsetWidth;

  }

  else if(place == 'right')

  {

    xorigin += ahref.offsetWidth;

  }

  else if(place == 'bottom')

  {

    yorigin += ahref.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(ahref, child);

}



function menuLower()

{

  menuGlobals.timer = setTimeout('menuStackShrink(null)', menuGlobals.delay);

}



var menuGlobals = new menuGlobalsObject();


