var pathRelativo = '../menu/';
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] = 'MARKA';
	lstMenu[1] = 'PRODUKTY';
	lstMenu[2] = 'US&#321;UGI';
	lstMenu[3] = 'IDŹ DO';
	lstMenu[4] = 'NEWS';
		
	for(var i=0; i<lstMenu.length; i++)
	{
		lstVoci[i] = new Array();
		lstURL[i] = new Array();
	}
	
	// VOCI DEI MENU A TENDINA
	
	// MENU 0
		
	lstVoci[0][0] = 'Historia';
	lstURL[0][0]  = '../brand/history.php';
	lstVoci[0][1] = 'Misja';
	lstURL[0][1]  = '../brand/misja.php';
	lstVoci[0][2] = 'Wartości';
	lstURL[0][2]  = '../brand/wartosci.php';
	lstVoci[0][3] = 'Ariston Thermo Group';
	lstURL[0][3]  = '../brand/atgroup.php';
	
	// MENU 1
	
	lstVoci[1][0] = 'Kotły gazowe';
	lstURL[1][0]  = '../products/kotly_gazowe.php';
	lstVoci[1][1] = 'Podgrzewacze elektryczne';
	lstURL[1][1]  = '../products/se.php';
	lstVoci[1][2] = 'Podgrzewacze gazowe';
	lstURL[1][2]  = '../products/sga.php';
	lstVoci[1][3] = 'Systemy Solarne';
	lstURL[1][3]  = '../products/solary.php';
	lstVoci[1][4] = 'Zasobniki';
	lstURL[1][4]  = '../products/zasobniki.php';
	lstVoci[1][5] = 'Kontakt z reprezentantem Ariston';
	lstURL[1][5]  = '../products/product_rh.php';
	lstVoci[1][6] = 'Lista dystrybutorów';
	lstURL[1][6]  = '../products/dystrybucja.php';
	lstVoci[1][7] = 'Poradnik doboru';
	lstURL[1][7]  = '../products/poradnik.php';

	// MENU 2
	
	lstVoci[2][0] = 'Punkty serwisowe';
	lstURL[2][0]  = '../services/aps.php';
	lstVoci[2][1] = 'Lista instalatorów';
	lstURL[2][1]  = '../services/instalatorzy.php';
	lstVoci[2][2] = 'Pliki do pobrania';
	lstURL[2][2]  = '../services/doc.php';
	lstVoci[2][3] = 'Dla projektantów';
	lstURL[2][3]  = '../services/service_p.php';
	lstVoci[2][4] = 'Dla instalatorów';
	lstURL[2][4]  = '../services/service_i.php';
	lstVoci[2][5] = 'Dla serwisantów';
	lstURL[2][5]  = '../dokumentacja/index.php';
//	lstVoci[2][5] = 'Professional Team';
//	lstURL[2][5]  = '#';

	// MENU 3
	
	lstVoci[3][0] = 'Ariston kondensacja';
	lstURL[3][0]  = 'http://www.aristonkondensacja.pl';
	lstVoci[3][1] = 'Ariston na świecie';
	lstURL[3][1]  = 'http://www.aristonheating.com';
	lstVoci[3][2] = 'Ariston Thermo Group';
	lstURL[3][2]  = 'http://www.aristonthermo.com';
 

	// MENU 4
	
	lstVoci[4][0] = 'Najnowsze wiadomości';
	lstURL[4][0]  = '../news/newsy_lst.php';
	lstVoci[4][1] = 'Napisali o Nas';
	lstURL[4][1]  = '../news/press_lst.php';
	lstVoci[4][2] = 'Newsletter - Ariston News';
	lstURL[4][2]  = '../newsletter/index.php';
	

	var winW = parseInt(document.documentElement.clientWidth);
	if(winW<817) winW=817;
	menuL = ((winW - 800) / 2) + 400 - 4;
	menuT = 25;
	menuH = 46;
	menuW = 368; 
	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 += '<img src="'+pathRelativo+'riga_v_grigia.gif" height="25" width="6">';
		htmlMenu += '<a href="#" onclick="apriChiudiTendina(' + i + ');">' + lstMenu[i] + '</a>';
		htmlMenu += '</div>';

		document.getElementById('menu').innerHTML += htmlMenu;
				
		setOpacita('tendina_' + i, 80)
		
		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('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';
	}
}
