// ==================================================
// ISTRUZIONI DI INIZIALIZZAZIONE
// ==================================================
// var screenW = screen.width
// var screenH = screen.height

// var pos_X_iniz=screenW-210;
document.write("<link rel='stylesheet' type='text/css' href='menu.css' />\n");

var pos_X_iniz=0;
var pos_Y_iniz=0;
var clickOui = false;
var bloc_x = pos_X_iniz;
var bloc_y = pos_Y_iniz;

var nodi;
var Foglia = ''
var RamoAperto = 'link/up.png'
var RamoChiuso = 'link/down.png'
var fraTarget = 'centro'


/*
	InitAlbero()
	Root=CreaAlbero()
	EndAlbero()
	new TreeMenu("menu1","block");

	if(navigator.appName.substring(0,3) == "Net")
		document.captureEvents(Event.MOUSEMOVE);
	document.onmousemove = get_mouse;
*/
function makeArray(length)
{
   this.length = length
}

function item(Livello, Tipo, Titolo, ToolTip , Riferimento, Icona, Ftarget)
{
    this.Livello = Livello
    this.Tipo = Tipo
    this.Titolo = Titolo
    this.ToolTip = ToolTip
    this.Riferimento = Riferimento
    if (Tipo=='Foglia')
       this.Icona = Icona
    else
       this.Icona = RamoChiuso;
    if (Ftarget!='')
        this.Ftarget = Ftarget
    else
       this.Ftarget = fraTarget
}
/* PROVA
function InitTitoli()
{

   var nNodi=15
   nodi = new makeArray(nNodi)
   nodi[ 0]=new item(0,'Ramo'  ,'Fortezze','','',RamoChiuso,'')
   nodi[ 1]=new item(1,'Foglia',  'Forte Valledrane','','1.htm',Foglia, fraTarget)
   nodi[ 2]=new item(1,'Foglia',  'Forte Corbin'    ,'','2.htm',Foglia, fraTarget)
   nodi[ 3]=new item(1,'Ramo'  ,  'Sbarramento Caldonazzo','','',RamoChiuso,'')
   nodi[ 4]=new item(2,'Foglia',    'Forte Busa Verle','','corsi/zip/RappresentazioneBinaria.exe',Foglia, fraTarget)
   nodi[ 5]=new item(2,'Foglia',    'Forte Cherle','','corsi/zip/RappresentazioneBinaria.exe',Foglia, fraTarget)
   nodi[ 6]=new item(2,'Ramo'  ,    'Rayon I','','',RamoChiuso,'')
   nodi[ 7]=new item(3,'Foglia',      'Forte Cherle','','corsi/zip/RappresentazioneBinaria.exe',Foglia, fraTarget)
   nodi[ 8]=new item(3,'Foglia',      'Forte Belvedere','','corsi/zip/RappresentazioneBinaria.exe',Foglia, fraTarget)
   nodi[ 9]=new item(1,'Foglia','Forte Oga','','corsi/zip/RappresentazioneBinaria.exe',Foglia, fraTarget)
   nodi[10]=new item(0,'Ramo'  ,'Trincee','','',RamoChiuso,'')
   nodi[11]=new item(1,'Foglia','Trincea A','','corsi/zip/RappresentazioneBinaria.exe',Foglia, fraTarget)
   nodi[12]=new item(1,'Foglia','Trincea B','','corsi/zip/RappresentazioneBinaria.exe',Foglia, fraTarget)
   nodi[13]=new item(1,'Ramo'  ,    'Rayon I','','',RamoChiuso,'')
   nodi[14]=new item(2,'Foglia',      'Forte CherleX','','corsi/zip/RappresentazioneBinaria.exe',Foglia, fraTarget)
}
*/
function InitAlbero(Titolo)
{
	document.write('<style type="text/css">\nA.ejsmenu { color:#000000;text-decoration:none }\n</style>')
	document.write('<DIV id=menu_dep STYLE="position:absolute; top:'+pos_Y_iniz+'; left:'+pos_Y_iniz+'">')
	document.write('<TABLE BORDER=0 CELLPADDING=1 CELLSPACING=1 WIDTH=170>')
	document.write('<TR><TD onMouseDown="testClick()" onMouseUp="testClick2()" style="cursor:move">');
//	document.write('<FONT SIZE=2 face="Verdana" COLOR=#FFCC00><B><a href="index.htm" Class=Radice>Home page</A></B></FONT></TD><TD BGCOLOR=#000000 align=RIGHT width=1><!IMG SRC=tree_js/plus.gif onClick="JavaScript:ApriTutto(this)"></TD></TR>')
//	document.write('<TR><TD BGCOLOR=#9FB1D8 NOWRAP colspan=2>');
	document.write('<TR><TD NOWRAP colspan=2 Class=Contenitore>');
}

function EndAlbero()
{
	document.write('</ul>');
	document.write('</TR>');
	document.write('</TABLE></DIV>')
	clickOui = false;
	bloc_x = pos_X_iniz;
	bloc_y = pos_Y_iniz;
}

function CreaAlbero()
{
//12/07/2008	document.write('<ul id="menu1" class="tree-menu">');

	// Menu 1ø Livello HomePage
	//if (document.URL.indexOf('index.htm')==-1)
   //  	document.write('    <li><a href="intro.htm" target='+fraTarget+'>Home Page</a></li>');

   InitTitoli();
   PrecLivAttuale=0;
   for (var i = 0; i < nodi.length; i++)
   {
       LivAttuale=nodi[i].Livello

       for (var j = PrecLivAttuale; j > LivAttuale ; j--)
           document.write("</ul>\n</li>\n");
     	 if (nodi[i].Tipo=='Foglia')
       	 {
             if (nodi[i].Riferimento!="")
                document.write("<li CLASS=box" + nodi[i].Icona + "><img src='" + nodi[i].Icona + "' width=30 height=30><a href='"+nodi[i].Riferimento+"' target="+nodi[i].Ftarget+">" +nodi[i].Titolo+"</a></li>");
			 else
                document.write("<li CLASS=nobox" + nodi[i].Icona + "><img src=" + nodi[i].Icona + " width=30 height=30><a NAME=Niente class=none>" +nodi[i].Titolo + "</a></li>\n");
         }
     	 else
        	 document.write("<li><a href='javascript:void(0)'>"+nodi[i].Titolo+"</a>\n<ul>\n");
       PrecLivAttuale=LivAttuale; 
    }
    for (var j = PrecLivAttuale; j > 0 ; j--)
        document.write("</ul>\n</li>\n");


	document.write('</ul>');
	document.write('</TR>');
	document.write('</TABLE></DIV>')
	clickOui = false;
	bloc_x = pos_X_iniz;
	bloc_y = pos_Y_iniz;
//   new TreeMenu("menu1","block");
//   new TreeMenu("menu1","none");
//	document.getElementById("menu_dep").style.display="block";
   
}


function testClick() 
{
		base_x = x-bloc_x;
		base_y = y-bloc_y;
		clickOui=true;
}

function testClick2() 
{
		clickOui=false;
}
function get_mouse(e)
{
	x = (navigator.appName.substring(0,3) == "Net") ? e.pageX : event.x+document.body.scrollLeft;
	y = (navigator.appName.substring(0,3) == "Net") ? e.pageY : event.y+document.body.scrollTop;
	if(clickOui && document.getElementById)
		{
			bloc_x = x-base_x;
			bloc_y = y-base_y;
		}
	document.getElementById("menu_dep").style.left = bloc_x
  	document.getElementById("menu_dep").style.top  = bloc_y
}

/*
 * DO NOT REMOVE THIS NOTICE
 *
 * PROJECT:   mygosuMenu
 * VERSION:   1.2.0
 * COPYRIGHT: (c) 2003,2004 Cezary Tomczak
 * LINK:      http://gosu.pl/dhtml/mygosumenu.html
 * LICENSE:   BSD (revised)
 */

function TreeMenu(id,modo) 
{

    this.init = function() 
    {
        if (!document.getElementById(this.id)) 
        {
            alert("Element '"+this.id+"' does not exist in this document. TreeMenu cannot be initialized");
            return;
        }
        this.parse(document.getElementById(this.id).childNodes, this.tree, this.id);
    }

    this.parse = function(nodes, tree, id)
    {
        for (var i = 0; i < nodes.length; i++) 
        {
            if (nodes[i].nodeType != 1) 
            {
                continue;
            }
            if (nodes[i].tagName.toLowerCase() == "li") {
                nodes[i].id = id + "-" + tree.length;
                tree[tree.length] = new Array();
                if (nodes[i].childNodes && this.hasUl(nodes[i].childNodes)) {
                    nodes[i].className = "section";
                    var a;
                    if (a = this.getA(nodes[i].childNodes)) {
                        a.id = nodes[i].id + "-a";
                        eval("document.getElementById('"+a.id+"').onclick = function() {"+
                            "self.click('"+nodes[i].id+"');"+
                        "}");
                    }
                } else {
                    //nodes[i].className = "box";
                }
            }
            if (nodes[i].tagName.toLowerCase() == "ul") {
                nodes[i].style.display = modo;
                id = id + "-" + (tree.length - 1);
                nodes[i].id = id + "-section";
                tree = tree[tree.length - 1];
            }
            if (nodes[i].childNodes) {
                this.parse(nodes[i].childNodes, tree, id);
            }
        }
    }

    this.hasUl = function(nodes) {
        for (var i = 0; i < nodes.length; i++) {
            if (nodes[i].nodeType != 1) {
                continue;
            }
            if (nodes[i].tagName.toLowerCase() == "ul") {
                return true;
            }
            if (nodes[i].childNodes) {
                if (this.hasUl(nodes[i].childNodes)) {
                    return true;
                }
            }
        }
        return false;
    }

    this.getA = function(nodes) 
    {
        for (var i = 0; i < nodes.length; i++) 
        {
            if (nodes[i].nodeType == 1) 
            {
                if (nodes[i].tagName.toLowerCase() == "a") 
                {
                    return nodes[i];
                }
                return false;
            }
        }
    }

    this.click = function(id) 
    {
        e1 = document.getElementById(id + "-section");
        e2 = document.getElementById(id);
        if (e1.style.display == "none") 
        {
            e1.style.display = "";
            e2.className = "section-open";
        }
        else
        {
            e1.style.display = "none";
            e2.className = "section";
        }
    }

    var self = this;
    this.id = id;
    this.tree = new Array();
    this.init();
}