// indice immagine di sfondo scelta casualmente;
var idxchosed = -1;

// lingue
var languages = Array (
 {"lang":"ITALIANO","dir":"it"},
 {"lang":"ENGLISH","dir":"en"}
);

// spazio dal footer al limite pagina
var SPACEFOOTER = 20;

// spazio tra menu e suo sottomenu
var SPACESUBMENUS_TOP = 20;

// spazio tra sottomenu aperto e successivo menu
var SPACESUBMENUS_DOWN = 20;


// parametri animazione ingresso menu
var menuDELTA_X = 5;
var menuDELTA_TIME = 20;
var menuWIDTH_MAX = 150;
var menuWIDTH_ANIM = 50;
var idxmenu = 0;
var idTimemenu = null;

// minima coordinata y per footer
var FOOTERYMIN = 600;

// array di menu
var menus = Array(
		{"idMenu":"azienda", "img":"menu01.png", "img_sel":"menu01_sel.png", "link":"azienda/index.php", "external":"0", "height":24, "submenu":Array()},
		{"idMenu":"collezione", "img":"menu02.png", "img_sel":"menu02_sel.png", "link":"collezione/index_fw2011.php", "external":"0","height":24, "submenu":Array(
								{"idMenu":"fw2011","img":"fw11.png", "img_sel":"fw11_selected.png", "link":"index_fw2011.php", "external":"0", "height":17},
								{"idMenu":"pe2011","img":"PE11.png", "img_sel":"PE11_selected.png", "link":"index_pe2011.php", "external":"0", "height":17},								
								{"idMenu":"fw2010","img":"03.png", "img_sel":"03_selected.png", "link":"index.php", "external":"0", "height":17}
								)
		},
		{"idMenu":"backstage", "img":"menu03.png", "img_sel":"menu03_sel.png", "link":"backstage/index_PE2011.php", "external":"0","height":24, "submenu":Array(
								{"idMenu":"pe2011","img":"PE11.png", "img_sel":"PE11_selected.png", "link":"index_PE2011.php", "external":"0", "height":17},
								{"idMenu":"fw2010","img":"03.png", "img_sel":"03_selected.png", "link":"index.php", "external":"0", "height":17}
								)
		},
		{"idMenu":"store", "img":"menu04.png", "img_sel":"menu04_sel.png", "link":"store/index.php", "external":"0","height":24, "submenu":Array(
								{"idMenu":"punti_vendita","img":"04.png", "img_sel":"04_selected.png", "link":"index.php", "external":"0", "height":17},
								{"idMenu":"rivenditori","img":"05.png", "img_sel":"05_selected.png", "link":"rivenditori.php", "external":"0", "height":17}								
								)
		},
		{"idMenu":"news", "img":"menu05.png", "img_sel":"menu05_sel.png","link":"news/index.php", "external":"0","height":24, "submenu":Array()},
		{"idMenu":"job", "img":"menu06.png", "img_sel":"menu06_sel.png","link":"job/index.php", "external":"0","height":24, "submenu":Array()},
		{"idMenu":"contatti", "img":"menu07.png", "img_sel":"menu07_sel.png","link":"contatti/index.php", "external":"0", "height":44, "submenu":Array()},
		{"idMenu":"shop", "img":"menu08.png", "img_sel":"menu08.png", "link":"shop/index.php", "external":"1", "height":24, "submenu":Array()}
);

function init(resizer)
{ 
	
	idxchosed = Math.floor(background_images.length*Math.random());
	var ri = document.getElementById("bkimgright");
	if(ri)
	{
		ri.src = background_images[idxchosed]['right'];
		document.getElementById("bkimgleft").src = background_images[idxchosed]['left'];
		window.onresize = resizer;
		resizer();
		
		var idLanguage = document.cookie.indexOf("lang=");
		
		if(idLanguage== -1)
		{
			// genera menu linguaggi
			var html = "";
			for(var i=0; i<languages.length; ++i)
			{
				html += "<a href='javascript:BuildMenu("+i+");setSession("+i+");'><img src='"+languages[i]["dir"]+"/images/lang.png' border='0' alt='"+languages[i]["lang"]+"'/></a><div style='height:15px;'></div>";	
			}
			document.getElementById("menu").innerHTML = html;
		}
		else
		{
			// genera menu standard
			idLanguage += 5;
			var j = document.cookie.indexOf(";",idLanguage);
			if(j == -1)
			{
				idLanguage = document.cookie.substring(idLanguage);
			}
			else
			{
				idLanguage = document.cookie.substring(idLanguage,j);
			}
			
			
			BuildMenu(parseInt(idLanguage));
		}
	}
}

// resize comportamento della pagina index
function doResizeType1()
{
	var bkdiv = document.getElementById("bk");
	var divimgright = document.getElementById("bkright");
	
	var bkimgright = document.getElementById("bkimgright");
	var h = bkdiv.clientHeight;
	if(h<background_images[idxchosed]['minHeight']) h = background_images[idxchosed]['minHeight'];
	var w = (background_images[idxchosed]['minWidth']*h)/background_images[idxchosed]['minHeight'];
	if(w<background_images[idxchosed]['minWidth'])
	{
		w = background_images[idxchosed]['minWidth'];
		h = (w*background_images[idxchosed]['minHeight'])/background_images[idxchosed]['minWidth'];
	}
	bkimgright.width = w;
	bkimgright.height = h;
	var ww = bkdiv.clientWidth-w;
	if(ww<background_images[idxchosed]['maxX']) ww = background_images[idxchosed]['maxX'];
	divimgright.style.left = ww+"px";

	var bkimgleft = document.getElementById("bkimgleft");
	var wl = ww;
	if(wl<background_images[idxchosed]['maxWidthLeft']) wl = background_images[idxchosed]['maxWidthLeft'];
	bkimgleft.width = wl;
	bkimgleft.height = h;
	var divimgleft = document.getElementById("bkleft");
	divimgleft.style.left = (ww-wl)+"px";
	
	var footer = document.getElementById("footer");
	var y = bkdiv.clientHeight-parseInt(footer.style.height)-SPACEFOOTER;
	if(y<FOOTERYMIN) y = FOOTERYMIN;
	footer.style.top = y+"px";

}

// resize comportamento della pagina azienda
function doResizeType2()
{
	var bkdiv = document.getElementById("bk");
	var divimgright = document.getElementById("bkright");
	
	var bkimgright = document.getElementById("bkimgright");
	var ww = bkdiv.clientWidth-background_images[idxchosed]['minWidth'];
	if(ww<background_images[idxchosed]['maxX']) ww = background_images[idxchosed]['maxX'];
	divimgright.style.left = ww+"px";	
	bkimgright.width = background_images[idxchosed]['minWidth'];
	bkimgright.height = background_images[idxchosed]['minHeight'];


	var bkimgleft = document.getElementById("bkimgleft");
	var wl = ww;
	if(wl<background_images[idxchosed]['maxWidthLeft']) wl = background_images[idxchosed]['maxWidthLeft'];
	bkimgleft.width = wl;
	bkimgleft.height = background_images[idxchosed]['minHeight'];
	var divimgleft = document.getElementById("bkleft");
	divimgleft.style.left = (ww-wl)+"px";
	
	var footer = document.getElementById("footer");
	var y = bkdiv.clientHeight-parseInt(footer.style.height)-SPACEFOOTER;
	if(y<600) y = 600;
	footer.style.top = y+"px";
}

function setSession(idx)
{ 
	var ExpireDate = new Date ();
	ExpireDate.setTime(ExpireDate.getTime() + (24 * 3600 * 1000));	
	document.cookie="lang="+idx+";path=/;expires="+ExpireDate;
}

function BuildMenu(idx)
{	
	// variabili esterne
	// menuActive menu livello 1 attivo
	// subMenuActive menu livello 2 attivo
	// menuAnim booleano: true = anima - false = non animare
	var y = 0;
	var y_submenu = 0;
	var html = "";
	var submenu = "";
	
	var dir = languages[idx]["dir"] + "/";
	var width = (menuAnim)? "1":"150";
	
	var m = 0;
	
	for(var i=0; i<menus.length; ++i)
	{	
		html += "<div id='m"+m+"' style='position:absolute;left:0px;top:"+y+"px; width:"+width+"px;height:" + menus[i]["height"] + "px;overflow:hidden;'>";
		++m;

		if(menus[i]["idMenu"] == menuActive)
		{   //alert("menu=" + menus[i]["idMenu"] + " height=" + menus[i]["height"]);
			html += "<img src='/" + dir + "images/" + menus[i]["img_sel"] +"' border='0' alt='' /></div>";
			y += menus[i]["height"];
			var submenus = menus[i]["submenu"];
			if(submenus.length > 0)
			{
				for(var j=0; j<submenus.length; ++j)
				{
					html += "<div id='m"+m+"' style='position:absolute;left:1px;top:"+y+"px; width:"+width+"px;height:" + submenus[j]["height"] + "px;overflow:hidden;'>";
					++m;
					if(submenus[j]["idMenu"] == subMenuActive)
					{
						html += "<img src='/" + dir + "images/" + submenus[j]["img_sel"] +"' border='0' alt='' />";
					}
					else
					{
						html += "<a href='"+submenus[j]["link"] +"'><img src='/" + dir + "images/" + submenus[j]["img"] +"' border='0' alt='' /></a>";
					}
					html += "</div>";
					y += submenus[j]["height"];
				}
				y += menus[i]["height"];
			}
		}
		/*else if(menus[i]["external"] == '1')
		{
			html += "<a href='"+menus[i]["link"]+"'><img src='/" + dir + "images/" + menus[i]["img"] +"' border='0' alt=''/></a></div>";
			y += menus[i]["height"];
		}*/
		else			
		{
			html += "<a href='/"+dir+menus[i]["link"]+"'><img src='/" + dir + "images/" + menus[i]["img"] +"' border='0' alt=''/></a></div>";
			y += menus[i]["height"];
		}
	}
	
	if(idx == 0)
	{
		// setSession(0);
		// dir = languages[0]["dir"] + "/";
		//document.getElementById('lingua_EN').style.display = "block";		
		//document.getElementById('lingua_IT').style.display = "none";
	}
	else if(idx == 1)
	{	
		// setSession(1);
		// dir = languages[1]["dir"] + "/";
		//document.getElementById('lingua_EN').style.display = "none";		
		//document.getElementById('lingua_IT').style.display = "block";
	}
	
	document.getElementById("menu").innerHTML = html;
	if(menuAnim) idTimemenu = setInterval(menuShower,menuDELTA_TIME);	
	
}

function menuShower()
{
	var i = 0;
	var w = 0;
	var div;
	while((div = document.getElementById("m"+i)))
	{
		w = parseInt(div.style.width) + menuDELTA_X;
		if(w<menuWIDTH_ANIM)
		{
			div.style.width = w+"px";
			return;
		}
		if(w>menuWIDTH_MAX) w = menuWIDTH_MAX;
		div.style.width = w+"px";
		++i;
	}
	if(w == menuWIDTH_MAX)
	{
		clearInterval(idTimemenu);
	}
}

/**
*
* Questa funzione gestisce la selezione dei punti vendita (mette il punto vendita selezionato col carattere rosso)
* e visualizza il fumetto in corrispondenza del punto vendita nella cartina dell'Italia
* Prende in input l'id del punto vendita e le coordinate x, y relative al punto vendita sulla cartina
*
*/
function select_pto_vendita(id, x, y)
{
	switch(id) 
	{
		case "parma":
				document.getElementById("store_details_center").innerHTML = "<b class='text_punti_vendita_fumetto'>PARMA</b>&nbsp;<span class='testo_interno_punti_vendita_fumetto'>Via Pisacane 14A</span>"
				document.getElementById("store_details").style.marginLeft = x;
				document.getElementById("store_details").style.marginTop = y;				
				document.getElementById("store_details").style.display = "block";
				document.getElementById(id).className = 'text_punti_vendita_hover';
			  	break;
		case "verona":
				document.getElementById("store_details_center").innerHTML = "<b class='text_punti_vendita_fumetto'>VERONA</b>&nbsp;<span class='testo_interno_punti_vendita_fumetto'>Via stella 5B</span>"
				document.getElementById("store_details").style.marginLeft = x;
				document.getElementById("store_details").style.marginTop = y;				
				document.getElementById("store_details").style.display = "block";				
				document.getElementById(id).className = 'text_punti_vendita_hover';
			  	break;
		case "napoli":
				document.getElementById("store_details_center").innerHTML = "<b class='text_punti_vendita_fumetto'>NAPOLI</b>&nbsp;<span class='testo_interno_punti_vendita_fumetto'>Via merliani 88</span>"
				document.getElementById("store_details").style.marginLeft = x;
				document.getElementById("store_details").style.marginTop = y;				
				document.getElementById("store_details").style.display = "block";				
				document.getElementById(id).className = 'text_punti_vendita_hover';
			  	break;
		case "riccione":
				document.getElementById("store_details_center").innerHTML = "<b class='text_punti_vendita_fumetto'>RICCIONE</b>&nbsp;<span class='testo_interno_punti_vendita_fumetto'>Viale Ceccarini 104/A</span>"
				document.getElementById("store_details").style.marginLeft = x;
				document.getElementById("store_details").style.marginTop = y;				
				document.getElementById("store_details").style.display = "block";				
				document.getElementById(id).className = 'text_punti_vendita_hover';
			  	break;
		case "caserta":
				document.getElementById("store_details_center").innerHTML = "<b class='text_punti_vendita_fumetto'>CASERTA</b>&nbsp;<span class='testo_interno_punti_vendita_fumetto'>Corso Trieste 25/29</span>"
				document.getElementById("store_details").style.marginLeft = x;
				document.getElementById("store_details").style.marginTop = y;				
				document.getElementById("store_details").style.display = "block";				
				document.getElementById(id).className = 'text_punti_vendita_hover';
			  	break;
		case "napoli2_1":
				document.getElementById("store_details_center").innerHTML = "<b class='text_punti_vendita_fumetto'>NAPOLI</b>&nbsp;<span class='testo_interno_punti_vendita_fumetto'>Piazza dei martiri 52</span>"
				document.getElementById("store_details").style.marginLeft = x;
				document.getElementById("store_details").style.marginTop = y;				
				document.getElementById("store_details").style.display = "block";				
				document.getElementById(id).className = 'text_punti_vendita_hover';
			  	break;
		case "capri":
				document.getElementById("store_details_center").innerHTML = "<b class='text_punti_vendita_fumetto'>CAPRI</b>&nbsp;<span class='testo_interno_punti_vendita_fumetto'>Via Le Botteghe 47</span>"
				document.getElementById("store_details").style.marginLeft = x;
				document.getElementById("store_details").style.marginTop = y;				
				document.getElementById("store_details").style.display = "block";				
				document.getElementById(id).className = 'text_punti_vendita_hover';
			  	break;
		case "frosinone":
				document.getElementById("store_details_center").innerHTML = "<b class='text_punti_vendita_fumetto'>FROSINONE</b>&nbsp;<span class='testo_interno_punti_vendita_fumetto'>Via Aldo Moro 205</span>"
				document.getElementById("store_details").style.marginLeft = x;
				document.getElementById("store_details").style.marginTop = y;				
				document.getElementById("store_details").style.display = "block";				
				document.getElementById(id).className = 'text_punti_vendita_hover';
			  	break;
		case "brescia":
				document.getElementById("store_details_center").innerHTML = "<b class='text_punti_vendita_fumetto'>BRESCIA</b>&nbsp;<span class='testo_interno_punti_vendita_fumetto'>Corso palestro 23</span>"
				document.getElementById("store_details").style.marginLeft = x;
				document.getElementById("store_details").style.marginTop = y;				
				document.getElementById("store_details").style.display = "block";				
				document.getElementById(id).className = 'text_punti_vendita_hover';
			  	break;
		case "panarea":
				document.getElementById("store_details_center").innerHTML = "<b class='text_punti_vendita_fumetto'>PANAREA</b>&nbsp;<span class='testo_interno_punti_vendita_fumetto'>Via San Pietro</span>"
				document.getElementById("store_details").style.marginLeft = x;
				document.getElementById("store_details").style.marginTop = y;				
				document.getElementById("store_details").style.display = "block";				
				document.getElementById(id).className = 'text_punti_vendita_hover';
			  	break;				
		case "salerno":
				document.getElementById("store_details_center").innerHTML = "<b class='text_punti_vendita_fumetto'>SALERNO</b>&nbsp;<span class='testo_interno_punti_vendita_fumetto'>Piazza XXIV maggio 14/A</span>"
				document.getElementById("store_details").style.marginLeft = x;
				document.getElementById("store_details").style.marginTop = y;				
				document.getElementById("store_details").style.display = "block";				
				document.getElementById(id).className = 'text_punti_vendita_hover';
			  	break;	
		case "milano":
				document.getElementById("store_details_center").innerHTML = "<b class='text_punti_vendita_fumetto'>MILANO</b>&nbsp;<span class='testo_interno_punti_vendita_fumetto'>Via Marghera 29</span>"
				document.getElementById("store_details").style.marginLeft = x;
				document.getElementById("store_details").style.marginTop = y;				
				document.getElementById("store_details").style.display = "block";				
				document.getElementById(id).className = 'text_punti_vendita_hover';
			  	break;				
	}
}

function deselect_pto_vendita(id)
{
	document.getElementById("store_details").style.display = "none";
	document.getElementById(id).className = 'text_punti_vendita';
}

/* Javascript mappa italia rivenditori */
var MapNomi = new Array ("0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19")
var MapSources = new Array ();
for (conta in MapNomi)
{
	MapSources[conta] = new Image();
	MapSources[conta].src = "../../images/italia/"+MapNomi[conta]+".png";
}

function RollOn(ImgNum)
{
	document.RollerMap.src=MapSources[ImgNum].src;
	clearTimeout(MapDefaultTimer);
}

function RollOut()
{
	clearTimeout(MapDefaultTimer);
	document.RollerMap.src=MapDefault.src;
	MapDefaultTimer=setTimeout("document.RollerMap.src=BaseMap.src;",200);
}
	
onload=SetDefaults;

function SetDefaults()
{
	if (ImgDefault!=-1)
		{
		BaseMap.src=MapSources[ImgDefault].src;
		document.RollerMap.src=MapSources[ImgDefault].src;
		}
}
/* FINE: Javascript mappa italia rivenditori*/	


// RECUPERA LE INFORMAZIONI CIRCA LE DIMENSIONI DELLA PAGINA (compatibile con tutti i browser)
function getSize()
{
	var viewportwidth;
	var viewportheight;
	var size = new Array();
	
	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	
	if (typeof window.innerWidth != 'undefined')
	{
	  viewportwidth = window.innerWidth,
	  viewportheight = window.innerHeight
	}
	
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	
	else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0)
	{
	   viewportwidth = document.documentElement.clientWidth,
	   viewportheight = document.documentElement.clientHeight
	}
	
	// older versions of IE
	
	else
	{
	   viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
	   viewportheight = document.getElementsByTagName('body')[0].clientHeight
	}
	
	size["h"] =  viewportheight;
	size["w"] =  viewportwidth;	
	
	return size;
}

