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] = 'ZNAČKA';
	lstMenu[1] = 'PRODUKT';
	lstMenu[2] = 'KONTAKT';
	lstMenu[3] = 'PRODEJCI';
	lstMenu[4] = 'SERVISY';
	lstMenu[5] = 'SOUBORY';
		
	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] = 'Historie';
	lstURL[0][0]  = 'index.php?action=history';
	lstVoci[0][1] = 'Mise';
	lstURL[0][1]  = 'index.php?action=mts_mission';
	lstVoci[0][2] = 'Hodnoty';
	lstURL[0][2]  = 'index.php?action=mts_values';
	lstVoci[0][3] = 'Ariston Thermo CZ';
	lstURL[0][3]  = 'index.php?action=mts_ceska';
	lstVoci[0][4] = 'Ariston Thermo Group';
	lstURL[0][4]  = 'index.php?action=mts_group';
	
	// MENU 1
	
	lstVoci[1][0] = 'Plynové kotle';
	lstURL[1][0]  = 'index.php?action=apk';
	lstVoci[1][1] = 'Elektrické ohřívače';
	lstURL[1][1]  = 'index.php?action=aeov';
	lstVoci[1][2] = 'Plynové ohřívače';
	lstURL[1][2]  = 'index.php?action=apov';
	lstVoci[1][3] = 'Nepřímo ohřívané zásobníky';
	lstURL[1][3]  = 'index.php?action=anozv';

	// MENU 2
	
	lstVoci[2][0] = 'Kontakty';
	lstURL[2][0]  = 'index.php?action=contact';
	lstVoci[2][1] = 'Ariston ve světě';
	lstURL[2][1]  = 'http://www.mtsgroup.com/ita/worldwide/index.cfm';
	lstVoci[2][2] = 'Ariston Thermo Group';
	lstURL[2][2]  = 'http://www.mtsgroup.com';	
  lstVoci[2][3] = 'MKM Praha';
	lstURL[2][3]  = 'http://www.mkm-praha.cz';	
  lstVoci[2][4] = 'VOTOP Praha';
	lstURL[2][4]  = 'http://www.votop.net';	
	
	// MENU 3
	
	lstVoci[3][0] = 'Distributoři';
	lstURL[3][0]  = 'index.php?action=distributors';
	lstVoci[3][1] = 'Prostor pro partnery';
	lstURL[3][1]  = 'index.php?action=partners';
	lstVoci[3][2] = 'FAQ';
	lstURL[3][2]  = 'index.php?action=faq';
 
	// MENU 4
	
	lstVoci[4][0] = 'Opravny elektrických ohřívačů vody';
	lstURL[4][0]  = 'index.php?action=servis_electro';
	lstVoci[4][1] = 'Opravny plynových kotlů a ohřívačů vody';
	lstURL[4][1]  = 'index.php?action=servis_gas';
	
	// MENU 5
	
	lstVoci[5][0] = 'Ceníky';
	lstURL[5][0]  = 'index.php?action=file_types_pl';
	lstVoci[5][1] = 'Katalogy';
	lstURL[5][1]  = '/index.php?action=file_types_c';
	lstVoci[5][2] = 'Ostatní dokumenty';
	lstURL[5][2]  = '/index.php?action=file_types_o';


	var winW = parseInt(document.documentElement.clientWidth);
	if(winW<817) winW=817;
	menuL = ((winW - 800) / 2) + 400 - 24;
	menuT = 20;
	menuH = 40;
	menuW = 398; 
	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 - 29;

	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';
	}
}
