
function getFirstTagChild(pere, tag){
  var fils = pere.childNodes;
  for(var num=0; num < fils.length; num++){
    if(fils[num].tagName == tag){
      return fils[num];
    }
  }
  return false;
}

function getBlockWidth(pere){
  var fils = pere.childNodes;
  var subLink;
  var textLarg;
  var largeur = 250;
  for(var num=0; num < fils.length; num++)
  {
	if(fils[num].tagName == "LI")
	{
		subLink = getFirstTagChild(fils[num], "A");
		textLarg = subLink.text.length;
	    if(textLarg > largeur)
		{
	      largeur = textLarg;
    	}
	}
  }
  return largeur;
}

function dropMenu(link){
  var subMenu = getFirstTagChild(link.parentNode, "UL");
  if(subMenu.style.display == "block"){
    subMenu.style.display = "none";
  } else {
    subMenu.style.display = "block";
	subMenu.style.left = link.offsetWidth + 4;
	subMenu.style.top = link.offsetTop;
	subMenu.style.width = 280;
//	subMenu.style.width = getBlockWidth(subMenu);
  }

  if (link.id == ""){
    var now = new Date();
    link.id = "linkMenu" + now.getMilliseconds();
  }
  link.onmouseout =
     function (){
       this.timeOutClose =
       setTimeout( 'getFirstTagChild(document.getElementById("'+ this.id +'").parentNode, "UL").style.display = "none"', 500 );
     };
  subMenu.linkControle = link;
  if (subMenu.id == ""){
    // originalmente o UL não tem id nem metodo onmouse(out|over). Esse teste adiciona tudo no primeiro uso.
    var now = new Date();
    subMenu.id = "subMenu" + now.getMilliseconds();
    subMenu.onmouseout =
       function (){
         this.timeOutClose = setTimeout( 'document.getElementById("'+ this.id +'").style.display = "none"', 333 );
       };
    subMenu.onmouseover =
       function (){
         clearTimeout(this.timeOutClose);
         clearTimeout(subMenu.linkControle.timeOutClose);
         subMenu.linkControle.onmouseout = false;
       };
  }
  return false;  // para anular o redirecionamento do link.
}

