function findPosX(obj){
  var curleft = 0;
  if (obj.offsetParent){
    while (obj.offsetParent){
      curleft += obj.offsetLeft
      obj = obj.offsetParent;
    }
  }
  return curleft;
}

function findPosY(obj){
  var curtop = 0;
  if (obj.offsetParent){
    while (obj.offsetParent){
      curtop += obj.offsetTop
      obj = obj.offsetParent;
    }
  }
  return curtop;
}

var HideQueue=[];
function HideProc()
{
  var n=HideQueue.shift();
  if(!n)
    return false;
  window.clearTimeout(n.timeout);
  n=n.node;
  if(n.x_visible==0)
    n.style.display="none";
  return true;
}

var ShowQueue=[];
function ShowProc()
{
  var n=ShowQueue.shift();
  window.clearTimeout(n.timeout);
  var node=n.node;
  if(!node)
    return false;
  if(node.x_visible==1)
  {
    var par=node.parentNode;
    if(node.style.display=='' || node.style.display=='none')
      while(HideProc());
    node.style.display="block";
    if(par.className=="rmenu")
    {
      var yoffs=(findPosY(par)-par.offsetTop)-(findPosY(node)-node.offsetTop);
      node.style.left=par.offsetLeft+par.offsetWidth-1;
      node.style.top=par.offsetTop+yoffs;
    }
    else
    {
      node.style.left=findPosX(par);
      node.style.top=findPosY(par)+par.offsetHeight;
    }
while(HideProc());
  }
  return true;
}

window.onload=function()
{
  for(var i=0; i<document.all.length; ++i)
  {
    var it=document.all[i];
    if(it.className=="menu")
    {
      it.onclick=function(e)
      {
        if(!e)
          e=window.event;

        var src=e.srcElement ? e.srcElement : e.target;
        while(src && src!=this)
        {
          if(src.className=='men')
            return true;
          src=src.parentNode;
        }

        for(var i=0; i<this.childNodes.length; ++i)
        {
          var it=this.childNodes[i];
          if(it.className=="men")
            if(it.style.display=='' || it.style.display=='none')
              it.style.display="block";
            else
              it.style.display="none";
        }
        e.cancelBubble=true;
        return false;
      }
    }
    if(it.className=="mei")
    {
      it.onmouseover=function(e)
      {
        this.className="meis";
      }
      it.onmouseout=function(e)
      {
        this.className="mei";
      }
    }





    if(it.className=="rmenu" || it.className=="dmenu")
    {
      it.onmouseover=function()
      {
        var zz=this.childNodes;
        for(j=0;j<zz.length;++j)
        {
          var node=zz[j];
          if(node.className=="men")
          {
            node.x_visible=1;
            ShowQueue.push({'node': node, 'timeout': window.setTimeout(ShowProc, 1)});
          }
        }
      }
      it.onmouseout=function()
      {
        var zz=this.childNodes;
        for(j=0;j<zz.length;++j)
        {
          var node=zz[j];
          if(node.className=="men")
          {
            node.x_visible=0;
            HideQueue.push({'node': node, 'timeout': window.setTimeout(HideProc, 1)});
          }
        }
      }
    }
  }
}
document.onclick=function()
{
  while(HideProc());
}

