//****************************************************************************
// PUBLIC FUNCTION:  populate_menu(container, content);
//
// PARAMETERS:
//  container:  string representing the span container that will hold the 
//              submenu.
//  content:    string representing the JavaScript array of links that will
//              be used to populate the provided container.
//
// DESCRIPTION:
// Focuses on populating a submenu container with submenu content from an
// array.
//****************************************************************************
function populate_menu(container, content)
{
  var menu = document.getElementById(container);
  menu.innerHTML=content.join("<br>");
}



//****************************************************************************
// PUBLIC FUNCTION:  position_menu(root_element, root_element_number, submenu_container, submenu_level);
//
// PARAMETERS:
//  root_element:         a reference to the original root menu element that  
//                        the rendered submenus come from.
//  root_element_number:  the ordinal position of the provided root element as
//                        it appears in the root menu.
//  submenu_container:    string representing the span container that will hold  
//                        the submenu.  this is what is moved.
//  parent_element:       string representing the specific container that will
//                        render the menu we are positioning.
//  element_number:       the ordinal position of the parent (which could be the
//                        same as the root number).
//  submenu_level:        integer representing the level number of the submenu. 
//
// DESCRIPTION:
// Focuses on positioning a submenu container against a parent element.
// The parent element can be another container or even a link within the
// container.
//
// The content array is passed so that, based on the container position,
// the links' positions within the container can be set.
//****************************************************************************
function position_menu(root_element, root_element_number, submenu_container, parent_element, element_number, submenu_level)
{
  shiftRight(root_element, root_element_number, submenu_container, submenu_level);
  shiftDown(root_element, root_element_number, submenu_container, parent_element, element_number, submenu_level);
}

function shiftRight(root_element, root_element_number, submenu_container, submenu_level)
{
  if(document.getElementById)
  {
    //find the parent menu on the page.
    var the_root_element = document.getElementById(root_element);
    if(the_root_element.style.width)
       the_root_element_width = new Number(the_root_element.style.width.replace(/px/, "")); 

    //find the submenu to move on the page.
    var the_submenu_element = document.getElementById(submenu_container);
    if(the_submenu_element.style.width)
       the_submenu_element_width = new Number(the_submenu_element.style.width.replace(/px/, "")); 
      
    the_submenu_element.style.position = "absolute";  
    the_submenu_element.style.left = (the_root_element_width*(root_element_number-1)) + (the_submenu_element_width*(submenu_level-1)) + "px";
  }
}

function shiftDown(root_element, root_element_number, submenu_container, parent_element, element_number, submenu_level)
{
  if(document.getElementById)
  {
    //find the root element on the page.
    var the_root_element = document.getElementById(root_element);
    if(the_root_element.style.height)
       the_root_element_height = new Number(the_root_element.style.height.replace(/px/, "")); 

    //find the parent element on the page.
    if(parent_element != '')
    {
      var the_parent_element = document.getElementById(parent_element);
      if(the_parent_element.style.height)
         the_parent_element_height = new Number(the_parent_element.style.height.replace(/px/, "")); 
    }

    //find the submenu to move on the page.
    var the_submenu_element = document.getElementById(submenu_container);
    if(the_submenu_element.style.height)
       the_submenu_element_height = new Number(the_submenu_element.style.height.replace(/px/, "")); 
      
    the_submenu_element.style.position = "absolute";  
    if (submenu_level==1)
        the_submenu_element.style.top = the_root_element_height + "px";
    else
        the_submenu_element.style.top = the_root_element_height + (the_parent_element_height*(element_number-1)) + element_number - 1 + "px";
  }
}
//****************************************************************************
// PUBLIC FUNCTION:  showhide_menu(container, show);
//
// PARAMETERS:
//  container:  string representing the span container that will hold the 
//              submenu.
//  show:       string value 'True' indicates to show the provided container.
//              string value 'False' indicates to hide the provided container.
//
// DESCRIPTION:
// Focuses on toggling a submenu container based on mouseover or mouseout
//****************************************************************************
function showhide_menu(container, show) 
{
  //alert("calling showhide_menu... ");
  if(show=="True")
  {
    document.getElementById(container).style.display="block";
  }
  else if(show=="False")
  {
    document.getElementById(container).style.display="none";
  }
}
