var ron="#EEAA33";    // Colore al MouseOver
var roff="#DDCCAA";   // Colore di default
var leftmargin=30;    // Distanza dal margine sinistro della pagina
var topmargin=73;     // Distanza dal margine superiore della pagina
var largo=130;        // Larghezza dei layers, quindi distanza (orizzontale) fra i sottomenu
var homewidth=55;     // Larghezza della cella Home
var itemheight=20     // Altezza delle voci

/*
L'array seguente contiene i testi che verranno visualizzati dal menu.
Nell'esempio (il menu di JsDir) trovate quattro elementi dell'array "voci" corrispondenti alle quattro voci del menu principale.
Il primo elemento degli array e' il nome del menu, gli elementi successivi sono i links contenuti nel singolo menu.
Il tasto "Home" non compare in questo array perche' viene inserito di default come primo elemento
*/
var voci=new Array();
voci[0]=new Array("Chi siamo","Presentazione","Dove siamo")
voci[1]=new Array("Come lavoriamo","Metodologia","Misure","Software");
voci[2]=new Array("Lavori","In corso","Eseguiti");
voci[3]=new Array("Risorse","Siti utili","Elettrobestiario");

/*
Questo array contiene invece i links che saranno aperti dalle singole voci dei sottomenu.
Da notare che il primo elemento degli array dev'essere una stringa vuota, infatti corrisponde non ad un link
da aprire, ma al titolo del sottomenu, cioe' al primo elemento dell'array "voci"
*/
var links=new Array();
links[0]=new Array("","presentazione.html","dovesiamo.html")
links[1]=new Array("","metodologia.html","misure.html","software.html")
links[2]=new Array("","incorso.html","eseguiti.html")
links[3]=new Array("","siti.html","elettrobestiario.html")

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Fine sezione personalizzabile.
* Le righe che seguono costituiscono il menu vero e proprio.
* La personalizzazione e' consigliata solo a webmaster un po' esperti di JavaScript.
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
var nn=document.layers?true:false,conta=0,last=0;

if (nn)
{
  document.write("<layer name=mtop. position=absolute left=" + leftmargin +
     " top="+ topmargin + " width="+homewidth+" height="+itemheight+" clip=0,0,"+homewidth+","+itemheight+" bgColor=" + roff +
     " visibility=visible onMouseOver=showdeps(last,false);mroll('mtop.') " +
     "onMouseOut=unmroll('mtop.')>&nbsp;<a href='prima.html' target='inf' class=menuNNb>" +
     "<b>Home</b></a></layer>");
  for (i=0;i<voci.length;i++)
  {
    var n=i;
    document.writeln("<layer name=mtop" + n + ". position=absolute left=" +
       eval(leftmargin+homewidth+largo*i) + " top=" + topmargin + " width=" + largo +
        " height="+itemheight+" clip=0,0," + largo + ","+itemheight+" bgColor=" + roff +
        " visibility=visible onMouseOver=MostraMenu(" + i + ");mroll('mtop" + i +
        ".');conta++ onMouseOut=last=" + i + ";unmroll('mtop" + i +
        ".');conta--><div align=center>&nbsp;<a href=javascript:mroll('mtop" + i +
        ".') class=menuNNb><b>" + voci[i][0] + "</b></a></div></layer>");
     for (l=1;l<voci[i].length;l++)
        document.writeln("<layer name=mdep" + i + "." + l + " position=absolute left=" +
           eval(leftmargin+homewidth+largo*i) + " top=" + eval(topmargin+itemheight*l) + " width=" + largo +
           " height="+itemheight+" clip=0,0," + largo + ","+itemheight+" bgColor=" + roff +
           " visibility=hidden onMouseOver=mroll('mdep" + n + "." + l +
           "');conta++ onMouseOut=unmroll('mdep" + n + "." + l + "');conta-->" +
           " &nbsp;<a href="+links[i][l]+" target='inf' onClick=mroll('mdep" + n + "." + l + "') class=menuNN><b>" + voci[i][l] + "</b></a></layer>");
     }
  }
  else
  {
     document.writeln("<div id=mleft align=center style=\"position:absolute;left:0;top:" +
        topmargin + ";width:30;  height:"+ itemheight
        +";background:url(img/right.gif);visibility:visible;\"></div>");

     document.writeln("<div id=mtop align=center style=\"position:absolute;left:" + leftmargin +
      ";top:" + topmargin + ";width:" + homewidth +"; height:" + itemheight + ";background:" +
      roff + ";visibility:visible;cursor:hand\" onMouseOver=showdeps(last,false);mroll('mtop') "
      + "onMouseOut=unmroll('mtop')><a href='prima.html' target='inf' onFocus=this.blur()><b>Home</b></a></div>");

      for (i = 0; i < voci.length; i++)
        {
          var n=i;
          document.writeln("<div id=mtop" + n + ". style=\"position:absolute;left:" +
          eval(leftmargin+homewidth+largo*i) + ";top:" + topmargin + "; width:" + largo +
          ";height:"+itemheight+";background:" + roff + ";visibility:visible;cursor:hand\" onMouseOver=MostraMenu(" + n +
          ");mroll('mtop" + n + ".');conta++ onMouseOut=last=" + n +
          ";unmroll('mtop" + n + ".');conta--><div align=center>" +
          "<b>" + voci[i][0] + "</b></div></div>");
          for (l=1;l<voci[i].length;l++)
            document.writeln("<div id=mdep" + i + "." + l + " style=\"position:absolute;left:" +
            eval(leftmargin+homewidth+largo*i) + ";top:" + eval(topmargin+itemheight*l) + "; width:" + largo +
            ";height:"+itemheight+";background:" + roff + ";visibility:hidden;cursor:hand\" onMouseOver=;mroll('mdep" + n +
            "." + l + "');conta++ onMouseOut=unmroll('mdep" + n + "." + l + "');conta-- " +
            ">&nbsp;<a href="+links[i][l]+" target='inf')><b>"+voci[i][l]+"</b></a></div>");
        }

     document.write("<div id=right align=center style=\"position:absolute;left:"+
        eval(leftmargin+homewidth+largo*voci.length)+";top:"+ topmargin +
        ";width:30;  height:"+itemheight+";background:url(img/left.gif);visibility:visible;\"></div>");

}

timer=setInterval("NascondiMenu()",1000)

function NascondiMenu()
{
  if (conta==0)
  {
     coloratutti(true)
     timer=setTimeout("coloratutti(false)",200);
     timer=setTimeout("showdeps(last,false)",250);
  }
}

function coloratutti(col)
{
  colore=col?ron:roff;
  for (i=0;i<voci.length;i++)
     for (j=1;j<voci[i].length;j++)
    {
       if (nn)
        document.layers["mdep"+i+"."+j].bgColor=colore;
        else
           if(document.all)
              document.all["mdep"+i+"."+j].style.background=colore;
          else
             document.getElementById('mdep'+i+"."+j).style.background=colore;
     }
}

function MostraMenu(n)
{
  showdeps(last,false);
  showdeps(n,true);
  last=n;
}

function showdeps(n,act)
{
  if (conta==0)
  {
    act?stat="visible":stat="hidden";
    if (nn)
       for (i=1;i<voci[n].length;i++)
          document.layers["mdep"+n+"."+i].visibility=stat;
    else
       for (i=1;i<voci[n].length;i++)
          if(document.all)
             document.all["mdep"+n+"."+i].style.visibility=stat;
          else
             document.getElementById('mdep'+n+"."+i).style.visibility=stat;
  }
}

function mroll(l)
{
  nn ? document.layers[l].bgColor=ron : (document.all) ? document.all[l].style.background=ron : document.getElementById(l).style.background=ron;
  document.getElementById ? document.getElementById(l).style.cursor=document.all ? 'hand' : 'pointer' : 'void(0)';
}

function unmroll(l)
{
  nn ? document.layers[l].bgColor=roff : (document.all) ? document.all[l].style.background=roff : document.getElementById(l).style.background=roff;
  window.status="";
}
