var aspetta = 100; // tempo di attessa del timer
var layerMenu = 'menutop'; // nome del layer che contiene il menu'
var layerMenuSub = 'menuSub'; // nome del layer che contiene il menu'
var curVoce = "1000";
var navMenu = new Array();
var isOver='si' // variabile per vedere se sono su un layer oppure no
var voce, stringa;
var mySez=""
var curW;
var curH;
var dim
var papa
var sotto=false;
var suSub='no'

// parametri personalizzazione font  e  colori
c_Tab="tabsubmenu"; //classe Tabella
c_Item="curSub"  // classe per le voci venu
c_ItemSu="curSubSu" // classe per le voci menuSu
voceOver="#003399"; //colore quando rollo su
voceOut="#0145BD";  //colore quando rollo giu
// funzione per netscape 4 che non becca evento sulle div; il nome del layer va specificato ()
function init() { 
  if (ns4) {
    document.menutop.onmouseover = vedoM
    document.menutop.onmouseout = viaMenu
	document.menuSub.onmouseover = vedoM
    document.menuSub.onmouseout = viaMenu
  }
  // se  sono nella sezione del  job  carico  mostro sola  la form dell'anagrafica se sono nella pagina cv
  //solo se  uso IE
  else if(document.getElementById && curPage=='jobs') {
        if(curSotto=='cv')mostraForm("CVPersona")
  }
  
}

function vedoSub(a,b){
  sotto=""
  sotto=a+'_'+b
  window.status=sotto
  curSub=new Array()
  curSub=eval(a)
  x=curSub[b][5]
  y=curSub[b][6] 
  vedo(layerMenuSub)
  riempi(sotto,'no')
  
  scrivi(layerMenuSub,myString)
  
  getWidth(layerMenuSub)
  moveTo(layerMenuSub,x,y) 
  suSub="si"
}

function keepPapa(){
if(document.getElementById && suSub=='si')document.getElementById(sotto).className="curSubSu"
}
function nascoSub(){
   if(document.getElementById && sotto)document.getElementById(sotto).className="curSub"
   nascondo(layerMenuSub)
   suSub="no"
}

// funzione dummy per richiamare lo show layer
function vedoM() { 
  isOver='si'
  vedo(layerMenu)
  if(suSub!="si")nascondo(layerMenuSub)
  if(document.getElementById)document.getElementById(papa).className="curSezSu"
  
} 

// funzione dummy per nascondere layer
function viaMenu() { 
  isOver='no'
  nascoT()
  
} 

// funzione per lanciare la funzione di hide
function nascoT() {

  if(ns4) { // in ns4 nascondo solo se isOver e' settata a "no"
    if(isOver=='no') {
	  clearTimeout(timerID);
      timerID=setTimeout('superNasc()',aspetta);
    }
  }
  else {
    clearTimeout(timerID);
    timerID=setTimeout('superNasc()',aspetta);
	if(document.getElementById && curPage!=papa)document.getElementById(papa).className="curSez"
	 if(document.getElementById && sotto)document.getElementById(sotto).className="curSub"
	  
  } 
}

function superNasc(){
   nascondo(layerMenu)
   nascondo(layerMenuSub)
}
// funzione che fa lo show del layer
function mostra(voce,page) { 
  papa=page
  curArray= new Array();
  curArray=eval(curBrand)
  x=curArray[voce][5]
  y=curArray[voce][6] 
  dim=curArray[voce][7]
  arrVoce=curBrand+'_'+voce
  riempi(arrVoce,'si'); // 2. costruisco la stringa del contenuto del sottomenu  
  if (curVoce!=voce) scrivi(layerMenu,myString); // 3. richiamo la funzione che scrive la stringa nel layer
  getWidth(layerMenu)
  moveTo(layerMenu,x,y); // 4. muovo il layer 
  vedo(layerMenu); // 5. mostro il layer
  curVoce=voce;
}  
 

// funzione che scrive il sottomenu
function riempi(voce,subM) {

   curArray= new Array();
   curArray=eval(voce)
   mySez="";
   myString=""
   
   start='<table border="0" cellpadding="0" cellspacing="0" class="curBg" width="'+dim+'">'; 
   
 
   dime='&nbsp;&nbsp;</div></td></tr>';
   fine='</table>';
   tSpacer='<tr><td  class="'+c_Item+'"><img src="/site/images/pix.gif" height="1"  width="1"></td></tr>'
	
	
// apro la table delle sottovoci   
     myString+='<table border="0" cellpadding="1" cellspacing="0" bgcolor="#FFFFFF"><tr><td align="left" >';
     myString+=start;
 // scrivo tante voci quante me ne risultano nell'array correnre
  		for (i=1;i<curArray.length;i++) { 
		     txt=curArray[i][curLang]
	         url='/site/'+curLext+'/'+curBrand+'/'+curArray[i][2]
			 voci=curArray[i][4]
			 // la voce  e uguale a 1 il path è assoluto
			 if(curArray[i][5]==1)url='/site/'+curArray[i][2]+'&lang='+lang;
	         if(curArray[i][5]==5)url=curArray[i][2]+'&lang='+lang; if(curArray[i][2]=="modelli")url=url='/site/'+curBrand+'/'+curArray[i][2]+'.php?brand='+curBrand+'&page=prodotti&sub='+curArray[i][3]+'&lang='+lang; 


			if(ns4){
			 myString+='<tr><td><img src="/site/images/pix.gif" height="22" width="3" border="0" alt="" align="absmiddle"></td><td align="left" nowrap ><div class="'+c_Item+'" onmouseover="this.className=\'curSezSu\'" onmouseout="this.className=\'curSez\'">';
			}
	       else {
		          if(voci==1){
				  id_menu=voce+'_'+i;
				   cella='<tr><td align="left" nowrap><div id="'+id_menu+'" class="'+c_Item+'" onmouseover="this.className=\'curSubSu\';vedoSub(\''+voce+'\','+i+
')"" onmouseout="this.className=\'curSub\'">'
				  }
		          else if(subM=='si'){
				   cella='<tr ><td align="left" nowrap><div class="'+c_Item+'" onmouseover="this.className=\'curSubSu\'; nascoSub()"" onmouseout="this.className=\'curSub\'">';
				  }
			      else if(subM=='no'){
				   cella='<tr ><td align="left" nowrap><div class="'+c_Item+'" onmouseover="this.className=\'curSubSu\';keepPapa()" onmouseout="this.className=\'curSub\'">';
				  }
		   	     myString+=cella+'<img src="/site/images/pix.gif" height="22" width="6" border="0" alt="" align="absmiddle">';
            }
		   
		    if(voci==1)myString+='<a href="#" class="'+c_Item+'" onmouseover="vedoSub(\''+voce+'\','+i+
')">'+ txt +'&nbsp;<b>&raquo;</b></a> ';
           
		    else if(subM=='si') {
		    myString+='<a href="'+url+'" class="'+c_Item+'" onmouseover="nascoSub()">'+ txt +' </a> ';
		    }
		   
		    else if(subM=='no') {
		        myString+='<a href="'+url+'" class="'+c_Item+'">'+ txt +' </a> ';
		   }
		   
		    myString+='';
            myString+=dime; 
	       
		   if(i<curArray.length-1)myString+='<tr><td  bgcolor="#FFFFFF" onmouseover="keepPapa()"><img src="/site/images/pix.gif" height="1"  width="1"></td></tr>'
        }
    
	myString+=fine; // chiudo la table
    myString+='</td></tr></table>';
    return mySez,myString;
}


// funzione che scrive il layer e il suo contenuto, ovvero scrive il menu
function writeMenu(){
  strMenu="";
  // scrivo layer con eventi correlati (show/hide)
  strMenu+='<div id="'+layerMenu+'" onmouseover="vedoM()" onmouseout="viaMenu()" align="left"></div>' 
  strMenu+='<div id="'+layerMenuSub+'" onmouseover="vedoM()" onmouseout="viaMenu()" align="left">fgsagsd</div>' 
  document.write(strMenu)
}
onload=init