//----------------------------------------- ale
var lang = 'ita_';
var lastPress ='03';
var aperto = '';
var tempo = false;
var popTimer = 0;
// tipo di browser
var isDOM = (document.getElementById ? true : false);
var isIE4 = ((document.all && !isDOM) ? true : false);
var isNS4 = (document.layers ? true : false);

// definizione del menu
gpaMenu = new Array();
gpaMenu[1] = new Array(0,'<b>Giuliano Azzinari</b>',lang+'01_giulianoAzzinari.php','<b>la struttura</b>',
lang+'01_people.php','<b>lavorare in GPA</b>',lang+'01_work.php');
gpaMenu[2] = new Array(0,'<b>attività</b>',lang+'02_context.php','<b>settori</b>',
lang+'02_areas.php');
gpaMenu[3] = new Array(0,'<b>gallery</b>',lang+'04_cs_home.php','<b>clienti</b>',
lang+'04_list.php');
gpaMenu[4] = new Array(0,'<b>metodo PI</b>',lang+'03_metodo_pi.php','<b>case history</b>',
lang+'03_GZ.php','<b>perchè</b>',
lang+'03_why.php','<b>quando</b>',
lang+'03_when.php');
gpaMenu[5] = new Array(0,'<b>news&amp;events</b>',lang+'06_events_03.php','<b>pubblicazioni</b>',
lang+'07_publishing_03.php');
gpaMenu[6] = new Array(0);
gpaMenu[7] = new Array(0);


function getRef(id) {
	if (isDOM) return document.getElementById(id);
	if (isIE4) return document.all[id];
	if (isNS4) return document.layers[id];
}

function getSty(id) {
	return (isNS4 ? getRef(id) : getRef(id).style);
}

// costruisco il menu
function menuMaker(){
	document.getElementById('menuShow').style.display='block';
	//determino x, y e imposto la distanza
	positionX = parseInt(findPosX('but1'));
	positionY = parseInt(findPosY('but1'))+67;
	spazioOr = 71;
	
	//alert(gpaMenu[2].length);
	if (!isDOM && !isIE4 && !isNS4) return;
	
	for(i=1; i<gpaMenu.length; i++){   // apro i tag div che contengono i sottomenu
	
		layerID='subMenu_'+i;
		str='';
		
		if (isDOM || isIE4) {
			str += '<div id="' + layerID + '" style="position: absolute; left: ' + (positionX+((i-1)*spazioOr)) + '; top: ' + positionY + ';  visibility: hidden;">';
			//alert(str);
		}
		
		if (isNS4) {
			str += '<layer id="' + layerID + '" left="' + (positionX+((i-1)*spazioOr)) + '" top="' + positionY + '"  visibility="hidden">';
		}
		
		//apro la tabella
		str += '<table border="0" cellpadding="0" cellspacing="0" class="itemBorder">';
		if(gpaMenu[i].length > 1){
			str += '<tr><td height="4"></td></tr>';
		}
		for(k=1; k<=((gpaMenu[i].length - 1)); k=k+2){
			str += '<tr><td style="padding-left: 4px; padding-right: 4px"  nowrap><a href="' + gpaMenu[i][k+1] + '" onmouseout="popOut(\'' + i + '\')" onmouseover="popOver(\'' + i + '\')" class="subMenuA"> ' + gpaMenu[i][k] + '</a></td></tr>';
		}
		if(gpaMenu[i].length > 1){
			str += '<tr><td height="4"></td></tr>';
		}
		str += '</table>';
		if (isDOM || isIE4) {
			str += '</div>';
			//alert(str);
		}
		
		if (isNS4) {
			str += '</layer>';
		}
		//alert(str);
		if (isDOM) {
			var newDiv = document.createElement('div');
			document.getElementsByTagName('body').item(0).appendChild(newDiv);
			newDiv.innerHTML = str;
			ref = newDiv.style;
			//ref.margin = '5px';
			ref.position = 'absolute';
			ref.visibility = 'hidden';
			ref.left='0px';
			ref.top='0px';
		}
		if (isNS4) {
			ref = new Layer(0);
			ref.document.write(str);
			ref.document.close();
		}
		/*if (isIE4) {
			document.body.insertAdjacentHTML('afterBegin', '<div id="' + layerID + 'div" ' + 'style="position: absolute; visibility: hidden">' + str + '</div>');
			ref = getSty(layerID + 'div');
		}*/
	}
}

function refreshMenu(){
	positionX = parseInt(findPosX('but1'));
	positionY = parseInt(findPosY('but1'))+67;
	for(i=1; i<gpaMenu.length; i++){
		document.getElementById('subMenu_'+i).style.left=(positionX+((i-1)*spazioOr));
		document.getElementById('subMenu_'+i).style.top=positionY;
	}
}

function popOver(lay){
	tempo=true;
	//if(lay!=aperto){
		document.getElementById('subMenu_'+lay).style.visibility='visible';
		document.getElementById('but'+lay).src=document.getElementById('but'+lay).src.replace('_newoff.','_new.');
		//if(aperto!=''){		
			chiudiTranne(lay);
		//}
	//}
	aperto=lay;
}
function chiudiTranne(tranne){
	for(i=1; i<9; i++){
		if(i!=tranne){
			document.getElementById('subMenu_'+i).style.visibility='hidden';
			document.getElementById('but'+i).src=document.getElementById('but'+i).src.replace('_new.','_newoff.');
		}
	}
}

function popOut(lay){
	tempo=false;
	popTimer = setTimeout('chiudi('+lay+')', 600);
}

function chiudi(lay){
	if(tempo==false){
		aperto='';
		document.getElementById('subMenu_' + lay).style.visibility='hidden';
		document.getElementById('but' + lay).src=document.getElementById('but'+lay).src.replace('_new.','_newoff.');
	}
}
//alert(gpaMenu);


//----------------------------------------- ale
function findPosX(oggetto){
	obj=document.getElementById(oggetto);
	var curleft = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	} else if (obj.x){
		curleft += obj.x;
	}
	return curleft;
}

function findPosY(oggetto){
	obj=document.getElementById(oggetto);
	var curtop = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}else if (obj.y){
		curtop += obj.y;
	}
	return curtop;
}


function quickFinder(){
	document.writeln('<select name="qfList" id="qfList" onchange="MM_jumpMenu(\'self\',this,0)" style="width: 180px">');
	document.writeln('<option value="#" selected>.: quickfinder</option>');
	//document.writeln('<option value="#" > </option>');
	document.writeln('<option value="'+lang+'home.php" >HOMEPAGE</option>');
	document.writeln('<option value="'+lang+'01_giulianoAzzinari.php" >PROFILO</option>');
	document.writeln('<option value="'+lang+'01_giulianoAzzinari.php" >Giuliano Azzinari</option>');
	document.writeln('<option value="'+lang+'01_people.php" >la struttura</option>');
	document.writeln('<option value="'+lang+'01_work.php" >lavorare in GPA</option>');
	document.writeln('<option value="'+lang+'02_context.php" >ATTIVITA</option>');
	document.writeln('<option value="'+lang+'02_context.php" >   attività</option>');
	document.writeln('<option value="'+lang+'02_areas.php" >   settori</option>');	
	document.writeln('<option value="'+lang+'04_cs_home.php" >PROGETTI</option>');
	document.writeln('<option value="'+lang+'04_cs_home.php" >gallery</option>');
	document.writeln('<option value="'+lang+'04_list.php" >clienti</option>');
	document.writeln('<option value="'+lang+'03_metodo_pi.php" >METODO PI</option>');
	document.writeln('<option value="'+lang+'03_metodo_pi.php" >metodo pi</option>');
	document.writeln('<option value="'+lang+'03_GZ.php" >case history</option>');
	document.writeln('<option value="'+lang+'03_why.php" >perché</option>');
	document.writeln('<option value="'+lang+'03_when.php" >quando</option>');
    document.writeln('<option value="'+lang+'06_events_03.php" >NEWS & PRESS</option>');
	document.writeln('<option value="'+lang+'06_events_03.php" >news & events</option>');
	document.writeln('<option value="'+lang+'07_publishing_03.php" >pubblicazioni</option>');
	document.writeln('<option value="'+lang+'06_videoLibrary.php" >VIDEO LIBRARY</option>');
	document.writeln('<option value="'+lang+'08_contacts.php" >CONTATTI</option>');
	//document.writeln('<option value="#" ></option>');
	//document.writeln('<option value="'+lang+'00_sitemap.htm" >mappa del sito</option>');
	document.writeln('</select>');
}
