/* parametri */
jjm_chiusuraInt=1000;
jjm_chiusuraVoceInt=300;

if (typeof(jjm_home)=="undefined") jjm_home = false;
jjm_selectPaeseId = "paesi";
jjm_selectProdottoId = jjm_home? "siteFindProduct:DdlSelectCategory": "siteHeader:siteFindProduct:DdlSelectCategory";
/**/

document.write("<div id=\"menu\" style=\"LEFT: 300px; POSITION: absolute; TOP: 33px\"></div>");

onLoad="";
window.onload = new Function("eval(onLoad)");

jjm_timerID="";
jjm_id = new Array;

onLoad += "jjm_inizializza();";

function jjm_inizializza()
{
	if (jjm_home)
	{
		selectPaeseWidth = 100;
		document.getElementById(jjm_selectPaeseId).style.width = selectPaeseWidth;
	}
	selectProdottoWidth = 200;
	document.getElementById(jjm_selectProdottoId).style.width = selectProdottoWidth;
	
	linkProdotti.onmouseover = new Function ("document.prodotti.src='images/prodotti_over.gif';jjm_apri('v1');");
	linkProdotti.onmouseout = new Function ("document.prodotti.src='images/prodotti.gif';jjm_chiudi('v1');");
	linkServizi.onmouseover = new Function ("document.servizi.src='images/pisite_nam_over.gif';jjm_apri('v2');");
	linkServizi.onmouseout = new Function ("document.servizi.src='images/pisite_nam.gif';jjm_chiudi('v2');");
	linkAzienda.onmouseover = new Function ("document.azienda.src='images/azienda_over.gif';jjm_apri('v3');");
	linkAzienda.onmouseout = new Function ("document.azienda.src='images/azienda.gif';jjm_chiudi('v3');");
}

function jjm_apri(id)
{
	if (jjm_timerID!="") clearTimeout(jjm_timerID);
	if (jjm_id[jjm_id.length-1] != id)
	{
		if (jjm_home && document.getElementById(jjm_selectPaeseId).style.width != selectPaeseWidth) document.getElementById(jjm_selectPaeseId).style.width = selectPaeseWidth;
		if (document.getElementById(jjm_selectProdottoId).style.width != selectProdottoWidth) document.getElementById(jjm_selectProdottoId).style.width = selectProdottoWidth;
		
		jjm_id = jjm_gerarchiaLeggi(id);
		var menuMatrice = new Array();
		var menuMatriceLength = 0;
		for (var i=0; i<jjm_id.length; i++)
		{
			menuMatrice[i] = new Array();
			var sottoVoci = jjm_SottoVociLeggi(jjm_id[i]);
			for (var j=0; j<sottoVoci.length; j++) menuMatrice[i][j] = sottoVoci[j];
			menuMatriceLength += sottoVoci.length;
		}
		var delta = new Array();
		delta[0] = 0;
		
		menu.style.left = 300+parseInt(jjm_parXML.getElementsByTagName(jjm_id[0])[0].getAttribute('x'));
		
		var str = "<table cellspacing=0 cellpadding=0 border=0>";
		for (var j=0; j<20 && menuMatriceLength>0; j++) // # max righe menu
		{
			str += "<tr>";
			for (var i=0; i<menuMatrice.length; i++)
			{
				if (delta==null || j<delta[i] || menuMatrice[i][j-delta[i]]==null) str += "<td></td>";
				else
				{
					var idCurr = menuMatrice[i][j-delta[i]].nodeName;
					var voce = menuMatrice[i][j-delta[i]].getAttribute('n');
					var classe = "jjm_menu";
					if (idCurr==jjm_id[i+1])
					{
						delta[i+1] = j;
						classe += "Sel";
					}
					str += "<td onmouseover=\"jjm_apri('"+ idCurr +"')\" onmouseout=\"jjm_chiudi()\" class=\""+ classe +"\"";
					var link = unescape(menuMatrice[i][j-delta[i]].getAttribute('l'));
					var esterna = menuMatrice[i][j-delta[i]].getAttribute('est');
					if (link=="") str += ">"+ voce +"</td>";
					else str += " onclick=\""+ (esterna? "": "location='"+ link +"'") +"\" style=\"cursor:hand;\"><a href=\""+ link +"\""+ (esterna? " target=\"_blank\"": "") +">"+ voce +"</a></td>";
					menuMatriceLength--;
					
					if (jjm_home)
					{
						if (j==0)
						{
							if (i==2) document.getElementById(jjm_selectPaeseId).style.width = "0";
							else if (i==1 && parseInt(menu.style.left)>300) document.getElementById(jjm_selectPaeseId).style.width = 66;
						}
						else if (j==9 && i==1) document.getElementById(jjm_selectProdottoId).style.width = 136;
					}
					else if ((j==1 || j==2) && i>0 || parseInt(menu.style.left)>450) document.getElementById(jjm_selectProdottoId).style.width = 0;
				}
			}
			str += "</tr>";
		}
		str += "</table>";
		menu.innerHTML = str;
	}
}

function jjm_chiudi2()
{
	if (jjm_id.length<=1)
	{
	  menu.innerHTML = "";
	  jjm_id = new Array();
	  
	  if (jjm_home && document.getElementById(jjm_selectPaeseId).style.width != selectPaeseWidth) document.getElementById(jjm_selectPaeseId).style.width = selectPaeseWidth;
      if (document.getElementById(jjm_selectProdottoId).style.width != selectProdottoWidth) document.getElementById(jjm_selectProdottoId).style.width = selectProdottoWidth;
	}
	else
	{
		jjm_apri(jjm_id[jjm_id.length-2]);
		jjm_timerID = window.setTimeout("jjm_chiudi2()", jjm_chiusuraVoceInt);
	}
}

function jjm_chiudi()
{
	if (jjm_timerID!="") clearTimeout(jjm_timerID);
	jjm_timerID = window.setTimeout("jjm_chiudi2()", jjm_chiusuraInt);
}

function jjm_carica()
{
	jjm_parXML = jjm_par.XMLDocument;
}

function jjm_gerarchiaLeggi(id)
{
	var gerarchia = new Array();
	var i = 0;
	gerarchia[0] = id;
	while (jjm_parXML.getElementsByTagName(gerarchia[i])[0].parentNode.nodeName != "dati")
	{
		gerarchia[i+1] = jjm_parXML.getElementsByTagName(gerarchia[i])[0].parentNode.nodeName;
		i++;
	}
	return gerarchia.reverse();
}
function jjm_SottoVociLeggi(id)
{
	return jjm_parXML.getElementsByTagName(id)[0].childNodes;
}

onLoad += "jjm_carica();";