/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

var md_id, md_ts, md_nivel=0, md_idMnu;
var md_niveis = new Array();
var md_selected = new Array();
var md_mouseX;
var md_mouseY;
var md_out_ts = 0;

function gebi(id)
{
   return document.getElementById(id);
}

function md_onOver(id, nivel, idMnu)
{
   if (nivel >= md_nivel  ||  md_ts == 0)
   {
      gebi(id).style.backgroundImage = 'url(images/botao_3.png)';
      md_id = id;
      md_ts = new Date().getTime();
      md_nivel = nivel;
      md_idMnu = idMnu;
   
      setTimeout("if (md_ts == "+md_ts+") md_open();", 500);   
   }
   md_out_ts = 0;
}

function md_onOut(id)
{
   gebi(id).style.backgroundImage = 'url(images/botao.png)';
   
   if (md_id == id)
   {
      md_id = null;
      md_ts=0;
   }
   md_out_ts = new Date().getTime();
   setTimeout("if (md_out_ts == "+md_out_ts+") md_closeAll();", 2000);
   md_activate_selected();
}

function md_closeAll()
{
   for (i=md_niveis.length; i>=0; --i)
      if (gebi(md_niveis[i]) != null)
         gebi(md_niveis[i]).style.display = 'none';
   md_activate_selected();
}

function md_open()
{
   for (i=md_niveis.length; i>=md_nivel; --i)
      if (gebi(md_niveis[i]) != null)
         gebi(md_niveis[i]).style.display = 'none';
   if (gebi(md_idMnu) != null)
   {      
      gebi(md_idMnu).style.position = 'absolute';
      gebi(md_idMnu).style.display = 'block';
      gebi(md_idMnu).style.zIndex = md_nivel;
      gebi(md_idMnu).style.top  = (findPosY(gebi(md_id)) - findPosY(gebi("menuDinamico")) - gebi(md_idMnu).clientHeight/2 + 16)+"px";
      gebi(md_idMnu).style.left = (203*(1+md_nivel))+"px";
      //      alert((findPosY(gebi(md_id)))+"px");
      md_activate_selected();
      md_niveis[md_nivel] = md_idMnu;
      md_selected[md_nivel] = md_id;
      md_activate_selected();
   }   
   setTimeout("md_ts = 0;", 200);   
}

function md_activate_selected()
{
   for (i=0; i<md_selected.length; ++i)
   try {
      if (gebi(md_selected[i]).style.backgroundImage == 'url(images/botao_2.png)')
         gebi(md_selected[i]).style.backgroundImage = 'url(images/botao.png)';
   } catch(e) {};
   for (i=0; i<md_nivel; ++i)      
      try {
         gebi(md_selected[i]).style.backgroundImage = 'url(images/botao_2.png)'
      } catch(e) {};
}

function md_ev_mouseX(evt)
{
   if (!evt) evt = window.event; if (evt.pageX) return evt.pageX; else if (evt.clientX)return evt.clientX + (document.documentElement.scrollLeft ?  document.documentElement.scrollLeft : document.body.scrollLeft); else return 0;
}

function md_ev_mouseY(evt)
{
   if (!evt) evt = window.event; if (evt.pageY) return evt.pageY; else if (evt.clientY)return evt.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollT7op : document.body.scrollTop); else return 0;
}

function follow(evt)
{      
   md_mouseX = parseInt(md_ev_mouseX(evt));
   md_mouseY = parseInt(md_ev_mouseY(evt));
}

document.onmousemove = follow;

