/*
0=> nome
1=> sotto voci  o link
2=> testo
3=> style css

Livelli :

0=> colori
1=>immagine voce
2=>immagine link
3=> classi css  (class voce, class link, class container, class <a></a>)

*/

function Ar_vocemenu01_class()
{
this.elen  = new Array();
this.ordinale = Ar_vocemenu01_ordinale;
}

function Ar_vocemenu01_ordinale(nome)
{for(var n=0;n<this.elen.length;n++)
	if(this.elen[n].dati[0]==nome)
		return n;
return -1;
}
var Ar_vocemenu01 = new Ar_vocemenu01_class();
function stmenu01_control()
{
this.voci  = new Array();
this.container;
this.stato=0;
// metodi
this.apri = stmenu01__apri;
this.chiudi = stmenu01__chiudi;
this.populate = stmenu01__populate;
}

function stmenu01__apri()
{if(this.container != undefined)
	this.container.apri();
for(var n=0;n<this.voci.length;n++)
if(this.voci[n][0] == 1)	 this.voci[n][1].apri();
else  this.voci[n][1].div.apri();
this.stato=1;

}

function stmenu01__chiudi()
{
var punt;
for(var n=0;n<this.voci.length;n++)
	{
	punt = this.voci[n][1];
	 if(this.voci[n][0] == 1)
	 		{
	 	    punt.stmenu.chiudi();
	 	    punt.chiudi();
	 	    if(punt.img != undefined && punt.img != null && punt.img_roll[0].length >0)
  				punt.img.src = punt.img_roll[0];
  			if(punt.colore != undefined && punt.colore[0] !=null)
  				punt.p_voce.style.backgroundColor = punt.colore[0];
	 	    }
     else  punt.div.chiudi();
	 }
this.stato=0;
if(this.container != undefined)
	this.container.chiudi();
}

function stmenu01__populate()
{
for(var n=0;n<this.voci.length;n++)
	 this.voci[n][1].populate();
if((typeof(this.container)).indexOf('string') >=0)
	this.container = new container_menu01_control(this.container,this);
}

function vocemenu01_control(dati)
// voce id  della voce, div_ elenco  id  dell'elenco da aprire, menu menu di appartenenza, contenitore id del div contenitore della voce
{this.dati=dati;
this.voce=dati[0];
this.div;
this.p_voce;
this.padre=null;
this.stmenu = new  stmenu01_control();
this.stato=0;
this.tipoelenco = 2;
this.img;
this.img_roll=new Array('','','');
this.colore=new Array('','','');
this.livello = 0;
// metodi
this.apri = vocemenu01__apri;
this.chiudi = vocemenu01__chiudi;
this.populate = vocemenu01_populate;
//eventi
this.onmouseover=vocemenu01_onmouseover;
this.onmouseout=vocemenu01_onmouseout;
this.onclick=vocemenu01_onclick;
// codice eseguito
this.arraypos=Ar_vocemenu01.elen.length;
Ar_vocemenu01.elen.push(this);
}

function vocemenu01__apri()
{
this.div.apri();
this.stato=1;
}

function vocemenu01__chiudi()
{
this.div.chiudi();
this.stato=0;
}

function vocemenu01_populate(dati)
{
this.div= new  div_control(this.dati[0]);
this.p_voce=qdocument.ObjById(this.voce);
this.div.tipoApCh=this.tipoelenco;
//eval("this.p_voce.onmouseover=function(){Ar_vocemenu01.elen["+this.arraypos+"].onmouseover()}");
//eval("this.p_voce.onmouseout=function(){Ar_vocemenu01.elen["+this.arraypos+"].onmouseout()}");
//eval("this.p_voce.onclick=function(){Ar_vocemenu01.elen["+this.arraypos+"].onclick()}");
this.p_voce.style.backgroundColor = this.colore[0];
if(this.img != undefined && (typeof(this.img)).indexOf('string') >=0)
	{    this.img=qdocument.ImgByName(this.img)
    this.img.src = this.img_roll[0];		}
this.stmenu.populate();
}
function vocemenu01_vuota()
{
	}

function vocemenu01_onmouseover()
{if(this.colore != undefined && this.colore[1] !=null)
  	this.p_voce.style.backgroundColor = this.colore[1];if(this.stmenu.stato != 1)
	{

  	if(this.img != undefined && this.img != null && this.img_roll[2].length >0)
  		this.img.src = this.img_roll[2];
    }
  else
  	 if(this.img != undefined && this.img_roll[3] != undefined && this.img_roll[3].length >0)
  		this.img.src = this.img_roll[3];
	}

function vocemenu01_onmouseout()
{
if(this.stmenu.stato != 1)
	{

  	 if(this.colore != undefined && this.colore[0] !=null)
  	this.p_voce.style.backgroundColor = this.colore[0];
  	if(this.img != undefined && this.img != null && this.img_roll[0].length >0)
  		this.img.src = this.img_roll[0];
  	}
  	else
  		{
  	 if(this.img != undefined && this.img != null && this.img_roll[1].length >0)
  		this.img.src = this.img_roll[1];
  		 if(this.colore != undefined && this.colore[2] !=null)
  	this.p_voce.style.backgroundColor = this.colore[2];
  	}	}

function vocemenu01_onclick()
{
var n;switch(this.stmenu.stato)
	{	case 0:
	if(this.img != undefined && this.img != null && this.img_roll[1].length >0)
  		this.img.src = this.img_roll[1];
  	 if(this.colore != undefined && this.colore[2] !=null)
  	this.p_voce.style.backgroundColor = this.colore[2];
  	this.stmenu.apri();

  	break;
  	case 1:
  	if(this.img != undefined && this.img != null && this.img_roll[0].length >0)
  		this.img.src = this.img_roll[0];
  	if(this.colore != undefined && this.colore[1] !=null)
  	this.p_voce.style.backgroundColor = this.colore[1];
  	this.stmenu.chiudi();
  		}
 }

 function linkmenu01_control(dati)
 {
this.dati=dati;
this.div;
this.tipoApCh=2;
this.stato=0;
this.img;
this.img_roll=new Array('','','');
this.colore=new Array('','','');
this.livello = 0;
this.padre=null;
//
this.populate=linkmenu01_populate;
//eventi
this.onmouseover=linkmenu01_onmouseover;
this.onmouseout=linkmenu01_onmouseout;
// codice eseguito
this.arraypos=Ar_vocemenu01.elen.length;
Ar_vocemenu01.elen.push(this);
 }
function linkmenu01_onmouseover()
{
 if(this.div.ogg!= null) {
  if(this.colore != undefined && this.colore[1] !=null  )
  	this.div.ogg.style.backgroundColor = this.colore[1];
 if(this.img != undefined && this.img != null && this.img_roll[1].length >0)
  		this.img.src = this.img_roll[1];
} }
function  linkmenu01_onmouseout()
{    if(this.div.ogg!= null) {
  	 if(this.colore != undefined && this.colore[0] !=null )
 		this.div.ogg.style.backgroundColor = this.colore[0];
    if(this.img != undefined && this.img != null && this.img_roll[0].length >0)
  		this.img.src = this.img_roll[0];
}}
function linkmenu01_populate(dati)
{
this.div= new div_control(this.dati[0]);
this.div.tipoApCh=this.tipoApCh;
this.div.ogg.style.backgroundColor = this.colore[0];
//eval("this.div.ogg.onmouseover=function(){Ar_vocemenu01.elen["+this.arraypos+"].onmouseover()}");
//eval("this.div.ogg.onmouseout=function(){Ar_vocemenu01.elen["+this.arraypos+"].onmouseout()}");
if(this.img != undefined && (typeof(this.img)).indexOf('string') >=0)
	{
    this.img=qdocument.ImgByName(this.img)
    this.img.src = this.img_roll[0];
		}}

 function container_menu01_control(nome,padre)
 {
 this.nome=nome;
this.ogg=qdocument.ObjById(nome);
this.stato=0;
this.livello = 0;
this.padre=padre;
this.intervallo = 20;
this.timer=-1;
//metodi
this.chiudi= container_menu01_chiudi;
this.apri= container_menu01_apri;
// codice eseguito
this.timerRef=div_Array.length;
div_Array.push(this);
this.ogg.style.display = 'none';
 }

function container_menu01_chiudi()
{
 // Inzia chiusura

          if(this.timer>0) clearInterval(this.timer)
          this.timer=setInterval("container_menu01_chiusura("+this.timerRef+")",this.intervallo);

}
function container_menu01_chiusura(div)
{
div=div_Array[div];
var res= 0, punt,n;
punt = div.padre.voci;

for(n=0;n<punt.length;n++)
	res |= (punt[n][1].div.stato & 3);
//alert(res)
if(res==0)
	{
	div.ogg.style.display = 'none';
	clearInterval(div.timer);
	div.timer=-1;
	//alert('chiuso')
	}
}

function container_menu01_apri()
{
this.ogg.style.display = 'block';
this.ogg.style.visibility = 'visible';
}

// ****************************************************

function creamenu(arrmenu,p,livello)
{
var menu = new Array();
var voce,n,punt;
livello =(livello == undefined) ?0:livello+1;
for( n=0; n<arrmenu.length; n++)
	{
	punt=arrmenu[n];
	voce =typeof(punt[1]) ;
	if(voce.indexOf('string') >=0)
		{
		var lnk = new linkmenu01_control(punt);
      	menu.push(new Array(0,lnk));
		}
	else
		{
		voce = new vocemenu01_control(punt);
		menu.push(new Array(1,voce));
		voce.stmenu.voci = creamenu(punt[1],voce,livello);

			}
     }

if(p!= undefined && p!=null)
	for( n=0; n<menu.length; n++)
	{
	punt=menu[n][1];
	punt.livello = livello;
	punt.padre=p;
	}
return menu;
}
var container =0;
function html_menu(menu,livelli)
{
var punt,ord,styl,classe,livello = menu[0][1].livello;
var cont = 'container'+container++;
document.write('<center><div id="'+cont+'" class="'+livelli[livello][3][2]+'" >');
//alert('<div id="'+cont+'" class="'+livelli[livello][8]+'" >'+livello);
var style ='position: relative; overflow: hidden; ' + (livello>0 ?  'display: none; ':'');
for(var n=0; n<menu.length; n++)
{  punt=menu[n][1];
   ord=Ar_vocemenu01.ordinale(punt.dati[0]);
   styl = style+punt.dati!= undefined && punt.dati[3] != undefined ?punt.dati[3]:''
   if(menu[n][0]>0)
   {
   	document.write('<div id="'+punt.voce+'" class="'+livelli[livello][3][0]+'" style="'+styl+'">');
   	document.write('<a href="" onclick="Ar_vocemenu01.elen['+ord+'].onclick();return false;" class="'+livelli[livello][3][3]);
   	document.write('" onmouseover="Ar_vocemenu01.elen['+ord+'].onmouseover();" ');
 	document.write('onmouseout="Ar_vocemenu01.elen['+ord+'].onmouseout();" >');
   	if(livelli[livello][1].length>0)
   				{   	   		    document.write('<img name="img_'+punt.voce+'" src="'+livelli[livello][1][0]+'" border="0" ');
   	   		    document.write((livelli[livello][3][4] != undefined ?livelli[livello][3][4]:'')+'></img>');
   	   		    punt.img = 'img_'+punt.voce;
   	   		    }
   	document.write(punt.dati[2]+'</a></div>');
    punt.stmenu.container=html_menu(punt.stmenu.voci,livelli);
    punt.img_roll=livelli[livello][1];   // inserisce array immagine
	}

   else
   	{
   	document.write('<div id="'+punt.dati[0]+'" class="'+livelli[livello][3][1]+'" style="'+styl+'">');
   	document.write('<a href="'+punt.dati[1]+'" class="'+livelli[livello][3][3]);
   	document.write('" onmouseover="Ar_vocemenu01.elen['+ord+'].onmouseover();" ');
 	document.write('onmouseout="Ar_vocemenu01.elen['+ord+'].onmouseout();" >');
	if(livelli[livello][2].length>0)
   				{
   				document.write('<img name="imgl_'+punt.dati[0]+'" src="'+livelli[livello][2][0]+'" border="0" ');
   				document.write((livelli[livello][3][4] != undefined ?livelli[livello][3][4]:'')+'></img>');
   	             //alert (livelli[livello][2][0]+"- "+livello)
   	   		    punt.img = 'imgl_'+punt.dati[0];
   	   		    }
    document.write(punt.dati[2]+'</a></div>');
    punt.img_roll=livelli[livello][2];   // inserisce array immagine
   	}

  	punt.colore=livelli[livello][0] ;    // inserisce array colore
   	punt.container = cont;
  }
document.write('</div></center>');
return cont;
}
function populate(menu)
{
for(var n=0; n<menu.length; n++)
   menu[n][1].populate();

	}

