var pathRelativo = '/images/';
var menuL, menuT, menuH, menuW, tendinaW;

var buf=0;
// ----------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------
function creaMenu()
{
	var htmlMenu;
	
	// creazione delle tendine
	for(var i=1; i<lstMenu.length; i++) clona('tendina_0',i);

	// compilazione dei menu
	for(var i=0; i<lstMenu.length; i++)
	{
		htmlMenu =  '<div width="100" onMouseOut="buf=0; HideAllMenu()" onMouseOver="SetBuf(1)" style="';
		htmlMenu += 'position:absolute; float: left; background-color: #FFFFFF; width: 100px;';
		htmlMenu += '';
		if (i == 0)
			htmlMenu += 'left:' + 0 +'px;';
		else if (i == 1)
			htmlMenu += 'left:' + 51 +'px;';
		else if (i == 2)
			htmlMenu += 'left:' + 130 +'px;';
		else if (i == 3)
			htmlMenu += 'left:' + 186 +'px;';
		else if (i == 4)
			htmlMenu += 'left:' + 271 +'px;';
		else if (i == 5)
			htmlMenu += 'left:' + 331 +'px;';
		htmlMenu += '">';
		htmlMenu += '<img src="'+pathRelativo+'riga_v_grigia.gif" height="25" width="6">&nbsp;';
		htmlMenu += '<a href="'+lstMenuhref[i]+'"';
		if (lstVoci[i].length > 0)
			htmlMenu += 'onMouseOver="apriChiudiTendina(' + i + '); buf=1;"';
		htmlMenu += '>' + lstMenu[i] + '</a>&nbsp;';
		htmlMenu += '</div>';

		document.getElementById('menu').innerHTML += htmlMenu;

		setOpacita('tendina_' + i, 80);

		if (lstVoci[i].length > 0)
		{
			htmlMenu1 = '<div style="background-color: #FFFFFF; line-height: 5px;" onMouseOver="SetBuf(1)" onMouseOut="buf=0; HideAllMenu()">';

			for(var k=0; k<lstVoci[i].length; k++)
			{
				htmlMenu1 += '<a href="' + lstURL[i][k] + '"';
				if (i == 3)
					htmlMenu1 += ' target="_blank"';
				htmlMenu1 += '>' + lstVoci[i][k] + '</a>';

				htmlMenu1 += '<img src="'+pathRelativo+'pixel_grigio.gif" height="5" width="' + (tendinaW-4) + '" style="padding: 0px; margin: 0px;" hspace="0" vspace="0">';

			}
			htmlMenu1 += '</div>';
			document.getElementById('tendina_' + i).innerHTML += htmlMenu1;
		}
	}
	ridimensiona();
}

function SetBuf(k)
{
	buf=k;
}

function HideAllMenu()
{
	setTimeout('HideAllMenuNext()',1000);
}

function HideAllMenuNext()
{
	if (buf == 0)
	{
		for(var i=0; i<lstMenu.length; i++)
			{document.getElementById('tendina_' + i).style.display = 'none';}
	}
}


// ---------------------------------------------------------------------------------------------------------------------
function apriChiudiTendina(n)
{
	// chiude tutte le altre
	for(var i=0; i<lstMenu.length; i++)
		{if(i!=n)document.getElementById('tendina_' + i).style.display = 'none';}
	
	// apre/chiude la tendina corretta
	if(valoreCSS('tendina_'+n, 'display')=='none') document.getElementById('tendina_' + n).style.display = 'block';
	else document.getElementById('tendina_' + n).style.display = 'none';
}

// ---------------------------------------------------------------------------------------------------------------------
function clona(id, suffisso) 
{
	var tags = ['div','select','img','input'] //Tag nell'oggetto da clonare
	if (!document.getElementById) { alert('Menu non disponibile');return; }
	
	var p = document.getElementById(id)
	if (p) 
	{
		var c = p.cloneNode(true);
		c.id = p.id.slice(0, p.id.length-1) + suffisso;
		for (var tag = 0; tag < tags.length; tag++) 
		{
			var list = c.getElementsByTagName(tags[tag]);
			for (var ogg = 0; ogg < list.length; ogg++) 
			{
				if (list[ogg].id) 
				{
					list[ogg].id = list[ogg].id.slice(0, list[ogg].id.length-1) + suffisso;
				}
			}	
		}		
	}	
	document.getElementsByTagName("BODY").item(0).appendChild(c);
}

// ---------------------------------------------------------------------------------------------------------------------
function valoreCSS(idOggetto, prop) 
{
	var oggetto = document.getElementById(idOggetto);
	if (oggetto.style[prop]) {return oggetto.style[prop];}
	else if (oggetto.currentStyle) {return oggetto.currentStyle[prop];}
	else if (document.defaultView && document.defaultView.getComputedStyle) 
	{
		prop = prop.replace(/([A-Z])/g,"-$1");
		prop = prop.toLowerCase();
		return document.defaultView.getComputedStyle(oggetto,"").getPropertyValue(prop);
	}
	else {return null;}
}

// ---------------------------------------------------------------------------------------------------------------------
function setOpacita(idOgg, percento)
{
	var el = document.getElementById(idOgg);
	// IE
	el.style.filter="alpha(opacity:"+percento+")";
	// ALTRI BROWSER
	percento = percento/100;
	el.style.KHTMLOpacity=""+percento+"";
	el.style.MozOpacity=""+percento+"";
	el.style.opacity=""+percento+"";
}

// ---------------------------------------------------------------------------------------------------------------------
function ridimensiona()
{
	var winW = parseInt(document.documentElement.clientWidth);
	if(winW<817) winW=817;
	menuL = ((winW - 800) / 2) + 400 - 4;

	for(var i=0; i<lstMenu.length; i++)
	{
		document.getElementById('tendina_' + i).style.left = (menuL + tendinaW*i+5) + 'px';
		document.getElementById('tendina_' + i).style.top = (menuT + menuH) + 'px';
	}
}

