var pathRelativo = 'menu2/';
var lstMenu = new Array();
var lstVoci = new Array();
var lstURL = new Array();
var menuL, menuT, menuH, menuW, tendinaW;

// ----------------------------------------------------------------------------------------
function initMenu()
{
	// MENU A TENDINA
	
	lstMenu[0] = '&nbsp;&nbsp;&nbsp;&nbsp;GO TO';
		
	for(var i=0; i<lstMenu.length; i++)
	{
		lstVoci[i] = new Array();
		lstURL[i] = new Array();
	}
	
	
	// MENU 3
	
	lstVoci[0][0] = 'Ariston in lume';
	lstURL[0][0]  = 'http://www.aristonheating.com';
	lstVoci[0][1] = 'AristonHeating.ro';
	lstURL[0][1]  = 'http://www.aristonheating.ro';
	lstVoci[0][2] = 'Ariston Thermo Group';
	lstURL[0][2]  = 'http://www.aristonthermo.com';
	lstVoci[0][3] = 'Ariston Thermo Romania';
	lstURL[0][3]  = 'http://www.aristonthermo.ro';
	

	var winW = parseInt(document.documentElement.clientWidth);
	if(winW<1050) winW=1050;
	menuL = ((winW - 1070) / 2) + 1 - 4;
	menuT = 25;
	menuH = 27;
	menuW = 50; 
	tendinaW = parseInt(menuW/lstMenu.length);
	
	creaMenu();

}

// ----------------------------------------------------------------------------------------
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 style="';
		htmlMenu += 'position:absolute; ';
		htmlMenu += 'width:' + (tendinaW-2) +'px;';
		htmlMenu += 'left:' + (tendinaW*i) +'px;';
		htmlMenu += '">';
		htmlMenu += '<a href="#" onclick="apriChiudiTendina(' + i + ');">' + lstMenu[i] + '</a>';
		htmlMenu += '</div>';

		document.getElementById('menu').innerHTML += htmlMenu;
				
		setOpacita('tendina_' + i, 70)
		
		for(var k=0; k<lstVoci[i].length; k++)
		{
			document.getElementById('tendina_' + i).innerHTML += '<a href="' + lstURL[i][k] + '">' + lstVoci[i][k] + '</a>';
			document.getElementById('tendina_' + i).innerHTML += '<br>';
			document.getElementById('tendina_' + i).innerHTML += '<img src="'+pathRelativo+'pixel_grigio.gif" height="5" width="' + (tendinaW-4) + '">';
			document.getElementById('tendina_' + i).innerHTML += '<br>';
		}
	}
	ridimensiona();
}

// ---------------------------------------------------------------------------------------------------------------------
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('Meniul nu este disponibil');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<1050) winW=1050;
	menuL = ((winW - 1070) / 2) + 1 - 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';
	}
}
