// JavaScript Document
// Menu  Creato da Cinzia Pagani
// CopyRight Media Group srl
// V.1.1 del 7/04/2003
// Aggiunta gestione evento onMouseOver , OnMouseOut

wordTree = new Array(0);
var  j=0;
var l=0;
//elemento 0 foglia; ELEMENTO 1: LIVELLO 0 CHIUSO; ELEMENTO 2: LIVELLO 0 APERTO; )
var leftIndent= 0;

function nodo(level, text, classe,  link1, target1, link2, target2) 
/* level: livello dell'elemento 0, 1, ...
   Text: testo dell'elemento
   classe: stile dell'elemento
   link1: Primo link
   target1: target del primo link
   link2: secondo link
   target2: target del secondo link  
 -------------------------------------------*/
{
var x;
        this.text = text;
        this.classe = classe
        this.link1 = link1;
		this.target1 = target1;
		this.link2 = link2;
		this.target2 = target2;
		this.level = level;
		this.son=new Array(0);
		if (level > 0 ){
			i=wordTree.length-1;
			while (wordTree[i].level>=level && i >0) i--;
			sons = wordTree[i].son;
			sons[sons.length]=this
		}
		
		wordTree[wordTree.length]=this;
}
function MouseOver(id, classe)
{
	var menu = document.getElementById('s'+id);
	menu.className=classe;	
}

function MouseOut(id, classe)
{
	var menu = document.getElementById('s'+id);
	menu.className=classe;	
}

function MenuClick(id) 
{
var menu = document.getElementById('f'+id).style;
//verifico lo status dell'attributo display: se è aperto lo chiudo e viceversa
	if (menu.display != "block")	
	{	
		menu.display = "block";				
	} 
	else
	{
		menu.display = "none";		
	}
//chiudo i menu aperti
		i=0;
		while(  document.getElementById('f'+i)!= null )
		{
			//verifico che l'id passato dalla funzione sia diverso da  quello cliccato
			if(i!= id)
				{					
					document.getElementById('f'+i).style.display= "none";					
				}
			i++;
		}
}

function Target2Frames(link1, target1, link2, target2) { 
	if (link1 != "" ) parent.frames[target1].location.href = link1;
	if (link2 != "" ) parent.frames[target2].location.href = link2;
 }

function print_tree(node, level) 
{
	var i;
	
	if(node.son.length>0) {  // è un nodo con figli
		
		document.writeln("<a href='#' onclick=\"MenuClick(" + j + ");Target2Frames('" + node.link1 + "', '" + node.target1 + "', '"  + node.link2 + "', '" + node.target2 + "')\";><div onMouseOver=\"MouseOver(" +l+ ", '" + node.classe+"2')\"  onMouseOut=\"MouseOut(" +l+ ", '" + node.classe+"')\" id=s" + l + " class=\"" + node.classe + "\">" + node.text + "</div></a>");	
		document.writeln("<span id=f"+ j+ " class=sub>");
		j++; l++;
		for(i=0; i<node.son.length; i++) 
			print_tree(node.son[i], level+1);
    	document.writeln("</span>");
	} 
	else {  // è una foglia
			
			document.write("<span   onClick=\"Target2Frames('" + node.link1 + "', '" + node.target1 + "', '"  + node.link2 + "', '" + node.target2 + "')\">");
			document.write("<div onMouseOver=\"MouseOver(" +l+ ", '" + node.classe + "2')\"  onMouseOut=\"MouseOut(" +l+ ", '" + node.classe + "')\" id=s"+ l+ " class=\"" + node.classe +"\">" )
			//document.write("<div  class=" + node.classe +">" );
			document.write(node.text );
			document.write("</div></span>");
			//document.writeln("<br>");
			l++;
		}
	
}

