var globalMenuItemId=0;
var globalMenuItemArray=new Array();

function TMenuItem(name,url,newWindow,posX,posY,sizeX,sizeY)
{
  this.id=globalMenuItemId++;
//alert(this.id);
  globalMenuItemArray[this.id]=this;
  
  this.name=new Array();
  this.url=new Array();
  this.newWindow=new Array();
  
  this.name[0]=name;
  this.url[0]=url;
  this.newWindow[0]=newWindow;

  if (name!="") this.linkCounter=1;
  else this.linkCounter=0;

  this.posX=posX;
  this.posY=posY;
  this.sizeX=sizeX;
  this.sizeY=sizeY;
  this.divSpacerY=14;

  this.mouseOverState=0;
  this.show=0;
  this.putted=0;
  this.htmlContent="";

  this.host=0;
  this.child=0;

  this.AddLink=AddLink;
  this.SetChild=SetChild;
  this.SetPos=SetPos;
  this.SetPosX=SetPosX;
  this.SetPosY=SetPosY;
  this.Put=Put;
  this.HandleMouseOver=HandleMouseOver;
  this.HandleMouseOut=HandleMouseOut;
  this.Show=Show;
  this.Hide=Hide;
  this.SetContent=SetContent;
  this.OpenUrl=OpenUrl;
  this.GetWidth=GetWidth;

  function AddLink(name,url,newWindow)
  {
    this.name[this.linkCounter]=name;
    this.url[this.linkCounter]=url;
    this.newWindow[this.linkCounter]=newWindow;
    this.linkCounter++;
  }
  
  function SetChild(child)
  {
    this.child=child;
    this.child.posX=this.posX;
    this.child.posY=this.posY+this.divSpacerY;
    this.child.host=this;
  }
  
  function SetContent(content)
  {
    this.htmlContent=content;
  }
  
  function SetPos(posX,posY)
  {
    this.posX=posX;
    this.posY=posY;
  }
  
  function SetPosX(posX)
  {
    this.posX=posX;
  }

  function SetPosY(posY)
  {
    this.posY=posY;
  }

  function OpenUrl(url,newWindow)
  {
    if (newWindow==1) window.open(url);
    else location.href=url;
  }
  
  function Put()
  {
    var htmlStr="";
    
    var classStr;
    if (this.host==0) classStr=" class='TMenuHostDiv'";
    else classStr=" class='TMenuChildDiv'";

//    document.write("<div id='menuItem"+this.id+"' style='position:absolute;'>Das ist ein Test</div>");
    htmlStr+="<div id='menuItem"+this.id+"' "+classStr+" style='z-index:100; position:absolute; visibility: hidden; width:"+this.sizeX+"px; height:"+this.sizeY+"; left: "+this.posX+"px; top: "+this.posY+"px;' onMouseOver='javascript:globalMenuItemArray["+this.id+"].HandleMouseOver();' onMouseOut='javascript:globalMenuItemArray["+this.id+"].HandleMouseOut();'>";
    if (this.host!=0) htmlStr+="<table border=0 cellspacing=2 cellpadding=0><tr><td>";

    if (this.linkCounter) htmlStr+="<table border=0 cellspacing=0 cellpadding=0>";

    for (i=0;i<this.linkCounter;i++)
    {

//      var targetStr;
//      if (this.newWindow[i]==1)  targetStr=" target='_blank';";
//      else targetStr=" target='_self';";

      if (this.host==0)
      {
        var mouseOverStr=" onMouseOver='this.className=\"TMenuItemHostOver\"'";
        var mouseOutStr=" onMouseOut='this.className=\"TMenuItemHostOut\"'";
        var classStr=" class='TMenuItemHostOut'";
      }
      else
      {
        var mouseOverStr=" onMouseOver='this.className=\"TMenuItemChildOver\"'";
        var mouseOutStr=" onMouseOut='this.className=\"TMenuItemChildOut\"'";
        var classStr=" class='TMenuItemChildOut'";
      }

      var onClickStr;
      if (this.url[i]!="#"&&this.url[i]!="") onClickStr=" onClick='javascript:globalMenuItemArray["+this.id+"].OpenUrl(\""+this.url[i]+"\",\""+this.newWindow[i]+"\");'";
      else onClickStr="";

      if (this.name[i]) htmlStr+="<tr><td"+mouseOverStr+mouseOutStr+onClickStr+classStr+"><nobr>"+this.name[i]+"</nobr></td></tr>";
   }
   
    if (this.linkCounter) htmlStr+="</table>";
   
    if (this.htmlContent!="") htmlStr+=this.htmlContent;
    
    if (this.host!=0) htmlStr+="</td></tr></table>";
    htmlStr+="</div>";

    document.write(htmlStr);
    this.putted=1;
  }
  
  function GetWidth()
  {
    return document.getElementById("menuItem"+this.id).offsetWidth;
  }
  
  function HandleMouseOver()
  {
    this.mouseOverState=1;
    this.Show();
    if (this.child)
    {
      if (this.child.mouseOverState==0) this.child.Show();
    }
  }
  
  function HandleMouseOut()
  {
    this.mouseOverState=0;
    if (this.child)
    {
      if (this.child.mouseOverState==0) this.child.Hide();
    }
    else
    {
      if (this.host!=0) this.Hide();
//      this.Hide();
    }
  }
  
  function Show()
  {
    if (this.show) return;
    if (!this.putted)
    {
      alert("ERROR: Can't show not putted item!");
      return;
    }
    if (Microsoft()) document.all['menuItem'+this.id].style.visibility="visible";
    else if (Mozilla()||Opera()) eval('document.getElementById("menuItem'+this.id+'").style.visibility="visible";');
    this.show=1;
  }
  
  function Hide()
  {
    if (this.show==0) return;
    if (Microsoft()) document.all['menuItem'+this.id].style.visibility="hidden";
    else if (Mozilla()||Opera()) eval('document.getElementById("menuItem'+this.id+'").style.visibility="hidden";');
    this.show=0;
  }
}

