 /**
 *	@author Kyo
 *	@function gestisce la struttura del sito  
 */

  var a_focus = new Array();		//array di elementi attualmente aperti
  var a_mask = new Array();		//array per il salvataggio dello zIndex del div mask
  var map;
  
 function init(){
	resizePage();
	if(document.getElementById('map_canvas')){
		//inizializzo google maps
		var latlng = new google.maps.LatLng(43.228679393765034,13.180155283042918);
		var myOptions = {
		  zoom: 14,
		  center: latlng,
		  mapTypeId: google.maps.MapTypeId.ROADMAP
		};
		map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
		var myLatlng = new google.maps.LatLng(43.228679393765034,13.180155283042918);
		var marker = new google.maps.Marker({
			position: myLatlng, 
			map: map,
			title:"Sede"
		});	
/*		google.maps.event.addListener(marker, 'click', function() {
			openMyMarker(marker,id);
		});
*/
		}
 } 
  
 function resizePage(){
 	var swidth = parseInt(document.body.offsetWidth,10);
	if(swidth<960){
		document.getElementById('divMain').style.marginLeft = 0;
		document.getElementById('divMain').style.left = '10px';
	}else if(swidth>=960){
		document.getElementById('divMain').style.marginLeft = '50%';
		document.getElementById('divMain').style.left = '-480px';
	}
	if(document.getElementById('divLeftPanel')&&document.getElementById('divArea')){
		if(document.getElementById('divLeftPanel').offsetHeight>=document.getElementById('divArea').offsetHeight){
			document.getElementById('divArea').style.height = (document.getElementById('divLeftPanel').offsetHeight + 100)+'px';
		}
	}
 }
 
 /**
  * oggetto div mask
  *
  */
  function mask(zIndex) {
   this.zIndex = zIndex;
  }


 /** intercetta il tasto premuto
  * @param {Event} evt evento scatenato 
  */
  function checkPressKey(evt){  
    var charCode = (evt.which) ? evt.which : evt.keyCode  
    if(charCode==27){
    	 	if (a_focus.length>0) {
 			closeDiv();
 			return false;
 		}
 		else {
 			return false;
 		}
    }else if(charCode==13){
    		var trg = getTarget(evt);
 		if(trg.getAttribute('function')){
 			eval(trg.getAttribute('function'));
 		}
    }
    return true;
  }
  
 /** visualizza un certo div ed il div mask se richiesto
  * @param {string} id  id del div da visualizzare
  * @param {boolean} mask  indica se devo visualizzare anche il div mask 
  * @param {boolean} esc indica se devo chiudere il div alla pressione dell'esc
  */
  function openDiv(id,mask,esc){
  	document.getElementById(id).style.display="block";
 	openMask(mask,id);
  	if(esc==false)
  		a_focus.push(id+"_noEsc");
 	else
 		a_focus.push(id);
  }

  /** visualizza il div di mascheramento
  * 
  * @param {boolean} show  indica se devo visualizzare il div mask
  */
  function openMask(show,id){
  	if(show!=false){
 		if(a_mask.length!=0){
 			//esiste gia' un div mask quindi cambio lo z-index
 			document.getElementById('divMask').style.zIndex=parseInt(document.getElementById(id).style.zIndex,10) - 1;						
 			a_mask.push(parseInt(document.getElementById(id).style.zIndex,10) - 1);
 		}else{
 			//non e' presente alcun div mask quindi lo visualizzo
 			document.getElementById('divMask').style.display="block";
 			a_mask.push(30);
 		}
 		a_focus.push('divMask');
 	}
  }

  /** chiude i div che hanno attualmente il focus
   * @param (Boolean) forza chiusura forzata del div
   * 
   */
  function closeDiv(forza){
 	var obj = a_focus[a_focus.length-1];	
 	//controllo se è un div che deve essere chiuso alla pressione dell'esc
 	if(obj.split('_noEsc').length==1){
 		//controllo se questo div ha un div mask vicino da chiudere
 		if(a_focus[a_focus.length-2]=='divMask'){
 			if(a_mask.length>1){
 				//questo non e' l'unico div mask presente quindi gli cambio zIndex
 				document.getElementById(obj).style.display = "none";
 				a_focus.pop();
 				a_focus.pop();				
 				a_mask.pop();
 				//assegno al div mask lo zIndex attualemente piu' alto
 				document.getElementById('divMask').style.zIndex = a_mask[a_mask.length-1];
 			}else{
 				//questo era e' l'unico div mask presente
 				document.getElementById(obj).style.display = "none";
 				document.getElementById('divMask').style.display = "none";
 				a_focus.pop();
 				a_focus.pop();				
 				a_mask.pop();
 			}
 		}else{
 			//chiudo il div senza div mask
 			document.getElementById(obj).style.display = "none";
 			a_focus.pop();
 		}
 	}else{
 	}
  }




  
