//****************************************************************************
// 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)
{
  //alert("calling populate_menu... ");
  var menu = document.getElementById(container);
  menu.innerHTML=content.join("<br>");
}



//****************************************************************************
// PUBLIC FUNCTION:  position_menu(container, parent, content);
//
// PARAMETERS:
//  container:  string representing the span container that will hold the 
//              submenu.
//  parent:     string value of the name of the element that will serve as 
//              the starting place to begin positioning the container 
//              provided.
//  content:    string representing the JavaScript array of links that will
//              be used to populate the provided container.
//
// 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(container, parent, content)
{
  //alert("calling position_menu... ");
  moveX(container, parent, content);
  moveY(container, parent, content);
}

function moveX(container, parent, content)
{
  if(document.getElementById)
  {
    var parent_element = document.getElementById(parent);
    var default_width = 200;

    parent_width = 0;    
    if(parent_element.style.width)
    {
      parent_width = new Number(parent_element.style.width.replace(/px/, "")); 
    }

    parent_left = 0;
    if(parent_element.style.left)
    {
      parent_left = new Number(parent_element.style.left.replace(/px/, ""));
    }

    var container_element = document.getElementById(container);
    var total = new Number(parent_left + parent_width);

    container_element.style.position = "absolute";
    container_element.style.width = parent_width + "px";
    container_element.style.left = total + "px";

    for(i=0;i<content.length;i++)
    {
      var content_link;
      if(i<10)
        content_link = container_element.id.replace(/container/, "link0"+i);
      else
        content_link = container_element.id.replace(/container/, "link"+i);

      var link_element = document.getElementById(content_link);
      link_element.style.left = total + "px";

      if(parent_width==0)
        link_element.style.width = default_width + "px";
      else
        link_element.style.width = parent_width + "px";
    }
  }
}

function moveY(container, parent, content)
{
  if(document.getElementById)
  {
    var parent_element = document.getElementById(parent);
    var default_height = 18;

    parent_height = 0;    
    if(parent_element.style.height)
    {
      parent_height = new Number(parent_element.style.height.replace(/px/, "")); 
    }

    //This value determines how many pixels the parent top offset is.
    parent_top = 15;
    if(parent_element.style.top)
    {
      parent_top = new Number(parent_element.style.top.replace(/px/, ""));
    }

    var container_element = document.getElementById(container);
    var total = new Number(parent_top + parent_height - 1);

    container_element.style.position = "absolute";
    container_element.style.height = parent_height + "px";
    container_element.style.top = total + "px";

    for(i=0;i<content.length;i++)
    {
      var content_link;
      if(i<10)
        content_link = container_element.id.replace(/container/, "link0"+i);
      else
        content_link = container_element.id.replace(/container/, "link"+i);

      var link_element = document.getElementById(content_link);
      link_element.style.height = parent_height + "px";

      if(parent_height==0)
        link_element.style.top = (parent_top+(default_height*i)) + "px";
      else
        link_element.style.top = (parent_top+(parent_height*i)) + "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";
  }
}