// JavaScript Document

var GMenuBar=null;
var GMenuTimer=-1;
var undefined;

function GMenuInit(Nome)
{
  if (!Nome) return;
  if (!document.getElementById) return;
  GMenuBar=document.getElementById(Nome);
  if (!GMenuBar) return;
  if (!GMenuBar.childNodes) {GMenuBar=null; return;}
  for (i=0;i!=GMenuBar.childNodes.length;i++)
   {
     divobj=GMenuBar.childNodes[i];
     if ((divobj.className == 'GMenuTopBox')|(divobj.className == 'GMenuBox')) 
     {
        for (k=0;k!=divobj.childNodes.length;k++)
        {
         aobj=divobj.childNodes[k];
         if (aobj.tagName=='A') 
         { 
          aobj.onmouseover=GMenuBarEnter; 
          aobj.onmouseout=GMenuBarExit;  
          ref=aobj.rel;
          if (ref)
          {
            var DivFiglio=document.getElementById(ref);
            if (DivFiglio) DivFiglio.GMenuMadre=divobj.id;
            if (divobj.className == 'GMenuTopBox') DivFiglio.GMenuMadre=null;
          }
         }
        } 
     }
   }
}

function GMenuBarEnter(event)
{
 var Gobj=this; 
 var GX = GpX(Gobj);
 var GY = GpY(Gobj);
 var GX1 = GX+Gobj.offsetWidth;
 var GY1 = GY+Gobj.offsetHeight;
 var subm = Gobj.rel;
 if (GMenuTimer!=undefined) if (GMenuTimer!=-1) { clearTimeout(GMenuTimer); GMenuTimer=-1; }
 if (subm) 
 {
  if (Gobj.className=='GSub') Gpos(subm,GX1+1,GY);
  else Gpos(subm,GX,GY1);
 }
 GParentsView(Gobj);
}

function Gpos(Nome,x,y)
{
 var Obj=document.getElementById(Nome);
 if (Obj)
 {
  Obj.style.top=y+'px';
  Obj.style.left=x+'px';
 }
}

function GpX(xobj)
{
	var curleft = 0;
	if (xobj)
	{
    if (xobj.offsetParent)
  	{ while (xobj.offsetParent) {curleft += xobj.offsetLeft; xobj = xobj.offsetParent; } 	}
  	else if (xobj.x) curleft += xobj.x;
  }
	return curleft;
}

function GpY(yobj)
{
	var curtop = 0;
	if (yobj)
	{
  	if (yobj.offsetParent)
  	{	while (yobj.offsetParent) { curtop += yobj.offsetTop;	yobj = yobj.offsetParent;	}	}
  	else if (yobj.y) curtop += yobj.y;
  }
	return curtop;
}


function GMenuBarExit(event)
{
 if (GMenuTimer!=undefined) if (GMenuTimer!=-1) clearTimeout(GMenuTimer); 
 GMenuTimer=setTimeout('GNascondiBarre()',600);
}

function GNascondiBarre()
{
 GMenuReset();
 GMenuView();
}

function GMenuReset()
{
 if (!GMenuBar) return;
 for (i=0;i!=GMenuBar.childNodes.length;i++)
  { if (GMenuBar.childNodes[i].className=='GMenuBox')  GMenuBar.childNodes[i].GMenuBoxView=false; }
}

function GMenuView()
{      
 if (!GMenuBar) return;
 for (i=0;i!=GMenuBar.childNodes.length;i++)
 { 
   divobj=GMenuBar.childNodes[i];  
   if (divobj.className=='GMenuBox') 
   {	    
     divobj.style.zIndex=1;
	   divobj.style.visibility=(divobj.GMenuBoxView==false)?'hidden':'visible'; 
   }
 }
}

function GParentsView(obj)
{
GMenuReset();
divobj=obj.offsetParent;  
if (divobj)
{
  if (divobj.className=='GMenuBox')
  {
     do
     { 
      MadreId=divobj.GMenuMadre;
      divobj=null;
      if (MadreId) 
      {
       divobj=document.getElementById(MadreId);
       divobj.GMenuBoxView=true;
      }
     } while(divobj);
     obj.offsetParent.GMenuBoxView=true;
  }   
}
figlio=(obj.rel)?document.getElementById(obj.rel):null;
if (figlio) figlio.GMenuBoxView=true;   
GMenuView();
}


