var visibleMenu = null, visibleName = "", visibleImgSrc = "", visibleTitle = null;
var timeoutID = 0;

function Trace (a)
{
  if (GetObjectByRef == null)
   return;
  GetObjectByRef ("Info").innerHTML += a + "<br />";
}

function GetObject (a)
{
  if (GetObjectByRef == null)
   return null;
  if (SupportLayers ())
  {
    var result = GetObjectByRef (a);
    if (result == undefined)
      result = document.layers ["LoMenu"].layers [a];
    if (result == undefined)
      result = null;
    return result;
  }
  return GetObjectByRef (a);
}

function GetEvent ()
{
  if (IEVersion () > 300)
    return event.srcElement;
}

function Reset ()
{
  visibleMenu = null;
  visibleName = "";
  visibleImgSrc = "";
  visibleTitle = null;
}

function doClearTimeout ()
{
  if (timeoutID > 0)
  {
    clearTimeout (timeoutID);
    timeoutID = 0;
  } // if
}

function hideActiveMenu (nm)
{
  doClearTimeout ();
  if (visibleMenu && visibleName != nm)
  {
    if (SupportLayers ())
    {
      //visibleTitle.src = visibleImgSrc;
      visibleMenu.visibility="hide";
    }
    else
    {
      visibleTitle.src = visibleImgSrc;
      visibleMenu.style.display="none";
    }
    visibleMenu = null;
    visibleName = "";
  }
}

function showMenu (nm, src, doPosition)
{
  if (GetObjectByRef == null)
   return;
  hideActiveMenu (nm);
  var oWorkItem=GetObject("idMenu" + nm), oSrc=GetObject("idNaam" + nm);
  var supportLayers = SupportLayers ();
  if (visibleName != nm)
  {
    visibleMenu = oWorkItem;
    visibleName = nm;
    if (!supportLayers)
      visibleImgSrc = oSrc.src;
    visibleTitle = oSrc;
  } // if
  var parent, positionLeft;
  if (doPosition)
  {
    parent = oSrc;
    positionLeft = 0;
    while (parent)
    {
      positionLeft += parent.offsetLeft;
      parent = parent.parentElement;
    }
  } // if
  if (!supportLayers)
    oSrc.src = src;
  if (doPosition)
  {
    oWorkItem.style.left=positionLeft + 20;
    oWorkItem.style.top = oSrc.offsetTop + oSrc.offsetHeight;
  }
  if (supportLayers)
  {
    oWorkItem.visibility="show";
  }
  else
    oWorkItem.style.display="";
}

function showThisMenu (nm)
{
  doClearTimeout ();
}

function showParentMenu (obj, nm)
{
  doClearTimeout ();
  if (SupportLayers ())
    obj.bgColor = "red";
  else
    obj.className = "MenuHover";
}

function hideMenu (nm)
{
  initHideMenu (nm);
}

function hideThisMenu (nm)
{
  initHideMenu (nm);
}

function hideParentMenu (obj, nm)
{
  initHideMenu (nm);
  if (SupportLayers ())
    obj.bgColor = "lightBlue";
  else
    obj.className = "MenuRef";
}

function initHideMenu (nm)
{
  doClearTimeout ();
  timeoutID = window.setTimeout("doHideMenu('" + nm + "');", 1000);
}

function setImage (obj, nm)
{
  hideActiveMenu ("*");
  obj.src = nm;
}

function doHideMenu (nm)
{
  hideActiveMenu ("*");
}

var menuID = 0;

function CChildMenu ()
{
  this.parentMenu = null;
  this.siblingMenu = null;
  return this;
}

function CSubMenu ()
{
  this.sPage = '';
  this.sBasePage = '';
  this.sTitle= '';
  this.sTekst = '';
  this.display = 'none';
  this.className = '';
  this.childMenu = null;
  this.parentMenu = null;
  this.siblingMenu = null;
  return this;
}

function CMenu ()
{
  this.activeMenu = new CSubMenu;
  this.rootMenu = this.activeMenu;
  this.baseFolder = '';
  this.offsetX = 0;
  this.offsetY = 20;
  return this;
}

CMenu.prototype.createSubMenu=function ()
{
  var newMenu = new CChildMenu;
  newMenu.parentMenu = this.activeMenu;
  this.activeMenu.childMenu = newMenu;
  this.activeMenu = newMenu;
}

CMenu.prototype.closeSubMenu=function ()
{
  this.activeMenu = this.activeMenu.parentMenu;
}

CMenu.prototype.addSiblingMenu=function ()
{
  var newMenu = new CSubMenu;
  newMenu.parentMenu = this.activeMenu.parentMenu;
  this.activeMenu.siblingMenu = newMenu;
  this.activeMenu = newMenu;
}

CMenu.prototype.setOffsetX=function (set)
{
  if (SupportLayers ())
    set -= 180;
  this.offsetX = set;
}

CMenu.prototype.setOffsetY=function (set)
{
  if (SupportLayers ())
    set += 20;
  this.offsetY = set;
}

CMenu.prototype.setBase=function (bsFolder)
{
  this.baseFolder = bsFolder;
}

CSubMenu.prototype.getHTML=function ()
{
  var content, width, doPosition;
  if (SupportLayers ())
  {
    doPosition = ", false";
    content = "<td><a href=\"#\" onmouseOver=\"showMenu('" + name + "', '" + thisMenu.baseFolder + img2Push + "'" + doPosition + ");\" onmouseOut=\"hideMenu('" + name + "', '" + thisMenu.baseFolder + img2 + "');\" >"
      + "<img src=\"" + thisMenu.baseFolder + img1 + "\" width=\"" + img1Width + "\" height=\"" + img1Height + "\" border=\"0\" /><br />"
      + "<img src=\"" + thisMenu.baseFolder + img2 + "\" width=\"" + img2Width + "\" height=\"" + img2Height + "\"  id=\"idNaam" + name + "\" border=\"0\"/><br />"
      + "</a></td>";
    thisMenu.activeMenu = "<layer id=\"idMenu" + name + "\"onmouseOver=\"showThisMenu('" + name + "');\" onmouseOut=\"hideThisMenu('" + name + "');\" class=\"MenuItem\" visibility=\"hide\" left=" + thisMenu.offsetX  + " top=" + thisMenu.offsetY + " style=\"position:absolute;\" width=75 bgColor=lightblue >";
    thisMenu.menuIndex = 0;
  }
  else
  {
    if (IEVersion () >= 400 || NSVersion () >= 500 || FireFoxVersion () >= 0)
    {
      if (this.sPage == "")
      {
        content = '<p class=' + this.className +' onmouseover="SelectMenu (this);" onmouseout="UnselectMenu (this);"';
      }
      else
      {
        content = '<p class=' + this.className + '><a href="' + this.sPage + '"' + ' onmouseover="SelectMenu (this);" onmouseout="UnselectMenu (this);"';
      } // if
      if (this.childMenu && this.childMenu.siblingMenu)
        content += ' onclick="ToggleDisplay (\'IDMenu' + (++menuID) + '\');"';
      content += ' Title="' + this.sTitle + '">' + this.sTekst + '</a></p>\n';
      if (this.childMenu && this.childMenu.siblingMenu)
      {
        content += '\n<div ID="IDMenu' + menuID + '" style="display:' + this.display + ';" ><table border="0" class="MenuTable"><tr><td>&nbsp;</td><td>' + this.childMenu.siblingMenu.getHTML () + '</td></tr></table></div>';
      }
    }
    else
    {
      if (this.sPage == "")
        content = '<span class=' + this.className + ' Title="' + sTitle + '">' + this.sTekst + '</span>&nbsp;\n';
      else
        content = '<a href="' + this.sPage + '" class=' + this.className + ' Title="' + sTitle + '">' + this.sTekst + '</a>&nbsp;\n';
    }
  }
  if (this.siblingMenu)
    return content + "\n" + this.siblingMenu.getHTML ();
  else
    return content + "\n";
}

CSubMenu.prototype.setVisibility=function (name)
{
  if (this.sBasePage == name)
  {
    this.display="block";
    return true;
  }
  if (this.childMenu && this.childMenu.siblingMenu && this.childMenu.siblingMenu.setVisibility (name))
  {
    this.display = "block";
    return true;
  }
  if (this.siblingMenu)
    return this.siblingMenu.setVisibility (name);
  return false;
}

CMenu.prototype.setVisibility=function ()
{
  var name = document.URL, pos;
  if (name.substring (0, 25) == "http://nele:6580/MyRoPhp/")
    name = name.substring (25, name.length);
  else
  {
    pos = name.indexOf ("/", 8);
    if (pos > 0)
      name = name.substring (pos + 1, name.length);
  }
  this.rootMenu.setVisibility (name);
}

CMenu.prototype.construct=function (menuName)
{
  var menu;
  if (GetObjectByRef)
    menu = GetObject (menuName);
  this.setVisibility ();
  if (IEVersion () > 300 || NSVersion () >= 500 || FireFoxVersion () >= 0)
  {
    menu.innerHTML = this.rootMenu.siblingMenu.getHTML ();
  }
  else if (NSVersion () >= 500 || IEVersion () > 0)
    menu.innerHTML = "<table border=0><tr>" + this.rootMenu.siblingMenu.getHTML () + "</tr></table>";
  else if (NSVersion () >= 400)
  {
    document.layers ["L" + menuName].document.write ("<table border=0><tr>" + this.content + "</tr></table>" + this.menu);
    document.layers ["L" + menuName].document.close ();
  }//if
  this.content = "";
  this.menu = "";
  this.offsetX = 0;
  this.offsetY = 60;
  /*
  var dbg, s, re;
  dbg = GetObject ("menuInfo");
  s = menu.innerHTML;
  s = s.replace (/&/g, "&amp;");
  s = s.replace (/</g, "&lt;");
  s = s.replace (/>/g, "&gt;<br />");
  dbg.innerHTML = s;
  */
}

var thisMenu = new CMenu ();

function makeMenu (sPage, sTitle, sTekst, className)
{
  thisMenu.addSiblingMenu ();
  thisMenu.activeMenu.sPage = sPage;
  while (sPage.length > 3 && sPage.substring (0, 3) == '../')
    sPage = sPage.substring (3, sPage.length);
  thisMenu.activeMenu.sBasePage = sPage;
  thisMenu.activeMenu.sTitle = sTitle;
  thisMenu.activeMenu.sTekst = sTekst;
  thisMenu.activeMenu.className = className;
}

function startSubMenu ()
{
  thisMenu.createSubMenu ();
}

function endSubMenu ()
{
  thisMenu.closeSubMenu ();
}

function constructMenu (menuName)
{
  thisMenu.construct (menuName);
}

function SetBase (bsFolder)
{
  thisMenu.setBase (bsFolder);
}

function SetOffsetX (set)
{
  thisMenu.setOffsetX (set);
}

function SetOffsetY (set)
{
  thisMenu.setOffsetY (set);
}



