var mappa, panel, pulsante, bottompannel, bottompannelabel, navigation, natop, overlay;
function init(){
	   initDhtmlgoodies_xpPane(Array('Emergenze/Altri eventi', 'Polizia Provinciale'),Array(false,false),Array());
       natop = document.getElementById("natop");
	   mappa = document.getElementById("map");
	   panel = document.getElementById("panel");
	   pulsante = document.getElementById("pulsante");
	   bottompannel = document.getElementById("bottompannel");
	   bottompannelabel = document.getElementById("bottompannelabel");
	   navigation = document.getElementById("navigation");
	   overlay = document.getElementById("overlay");
	   // mappa.style.width = "80%";
	   panel.style.right = "0px";
	   navigation.style.right = panel.style.right;
	   natop.style.right = "250px";
	   pulsante.style.right = "250px";
	   bottompannel.style.bottom = "20px";
	   bottompannelabel.style.bottom = "90px";
		// IE HACK -- Necessari solo per IE6, inutili per tutti gli altri browser
     	if (xIE6) {
			bottompannel.style.height = "73px";
			document.getElementById("cercaindirizzo").style.margin = "0";
			document.getElementById("cercaiitinerario").style.margin = "0";
     	}	   
	   // if (/Opera[\/\s](\d+\.\d+)/.test(navigator.userAgent)){panel.style.position="relative";panel.style.cssFloat="right";}	
	   // resizemap()
}
function slideRight(){
	var panelRight = parseInt(panel.style.right);
	if(panelRight == -250){pulsante.getElementsByTagName("a")[0].href="javascript:slideLeft()"; pulsante.getElementsByTagName("a")[0].className="slideleft"}
	else if(panelRight > -250){
		var offeset = (panelRight == -240)?10:20;
   		mappa.style.width = parseInt(mappa.style.width) + offeset + "px";				
		bottompannel.style.width = mappa.style.width;
		bottompannelabel.style.width = mappa.style.width; 
		panel.style.right = panelRight - offeset + "px";	
		navigation.style.right = panel.style.right
		natop.style.right = parseInt(natop.style.right) - offeset + "px";
		pulsante.style.right = parseInt(pulsante.style.right) - offeset + "px";		
	    // gestione velina
 	    overlay.style.left = (parseInt(overlay.style.left) + ((overlay.className == "map-overlay")?offeset/2:offeset)) + "px";	   
        setTimeout("slideRight()",10);
		// aggiorniamo la mappa geocms
		gmap.checkResize();		  
    }
}
function slideLeft(){
	var panelRight = parseInt(panel.style.right);
	if(panelRight == 0){pulsante.getElementsByTagName("a")[0].href="javascript:slideRight()"; pulsante.getElementsByTagName("a")[0].className="slideright"}
	else if(panelRight < 0){
			var offeset = (panelRight == -10)?10:20;
            mappa.style.width = parseInt(mappa.style.width) - offeset + "px";	
			bottompannel.style.width = mappa.style.width; 
			bottompannelabel.style.width = mappa.style.width; 
			panel.style.right = panelRight + offeset + "px";
			navigation.style.right = panel.style.right
			natop.style.right = parseInt(natop.style.right) + offeset + "px";
			pulsante.style.right = parseInt(pulsante.style.right) + offeset + "px";
		    // gestione velina
	 	    overlay.style.left = (parseInt(overlay.style.left) - ((overlay.className == "map-overlay")?offeset/2:offeset)) + "px";	   
            setTimeout("slideLeft()",10);
			// aggiorniamo la mappa geocms
			gmap.checkResize();		  
    }
}
function slideDown(){
	if(parseInt(bottompannelabel.style.bottom) == 20){
		bottompannelabel.getElementsByTagName("a")[0].href="javascript:slideUp()";
		bottompannelabel.getElementsByTagName("a")[0].className="slideup";
	}
	else if(parseInt(bottompannel.style.bottom) <= 20 && parseInt(bottompannel.style.bottom) > -50){
      bottompannel.style.bottom = parseInt( bottompannel.style.bottom) - 10 + "px";
      bottompannelabel.style.bottom = parseInt( bottompannelabel.style.bottom) - 10 + "px";
	  mappa.style.height = parseInt(mappa.style.height) + 10 + "px";
	  // gestione velina
	  if (overlay.className == "map-overlay") {overlay.style.top = (parseInt(overlay.style.top) + 4) + "px";}	   
	  setTimeout("slideDown()",10);
	  // aggiorniamo la mappa geocms
	  gmap.checkResize();		  
       }
}
function slideUp(){
	if(parseInt(bottompannelabel.style.bottom) == 90){
		bottompannelabel.getElementsByTagName("a")[0].href="javascript:slideDown()";
		bottompannelabel.getElementsByTagName("a")[0].className="slidedown"
	}
	else if(parseInt(bottompannel.style.bottom) < 20 && parseInt(bottompannel.style.bottom) >= -80){
      bottompannel.style.bottom = parseInt( bottompannel.style.bottom) + 10 + "px";
	  bottompannelabel.style.bottom = parseInt( bottompannelabel.style.bottom) + 10 + "px";
	  mappa.style.height = parseInt(mappa.style.height) - 10 + "px";
	  // gestione velina
 	  if (overlay.className == "map-overlay") {overlay.style.top = (parseInt(overlay.style.top) - 4) + "px";}
	  setTimeout("slideUp()",10);
	  // aggiorniamo la mappa geocms
	  gmap.checkResize();		  
       }
}
function resizemap(w, h) {
	var offset = (xFF)?2:(xIE)?3:2;
	var bottompannelHeight = (parseInt(bottompannelabel.style.bottom) == 90)?66:-3;
	mappa.style.height = (h - bottompannelHeight - offset)+ "px";
	mappa.style.width = w - parseInt(natop.style.right) + "px";
	
	// velina
	resizeOverlay();

	bottompannel.style.width = mappa.style.width;
	bottompannelabel.style.width = bottompannel.style.width;
	// panel.style.height = y - 147 + "px";
}

function changelight(a,b,c,d){
		document.getElementById(a).style.display = "block";
		document.getElementById(b).style.display = "none";
		document.getElementById(c).className="on";
		document.getElementById(d).className="off";
}
function avanzata(sez, titolo, avanzata){
	mydiv=document.getElementById("ricercavanzata").getElementsByTagName("div");
	for (x=0; x<mydiv.length; x++){mydiv[x].style.display="none"}
	var sezione = document.getElementById(sez);
	sezione.style.display="block";
	for(i=0; (a = document.getElementsByTagName("style")[i]); i++) {
		if (a.getAttribute("title") == "avanzata") {void(a.disabled=!avanzata);}
	}
	document.getElementById("ricercavanzata").className="accesa";
	var objBody = document.getElementsByTagName("body").item(0);
	var objOverlay = document.createElement("div");
	objOverlay.setAttribute('id','overlay');
	objOverlay.style.position = 'absolute';
	objOverlay.style.top = '0';
	objOverlay.style.left = '0';
	objOverlay.style.zIndex = '90';
 	objOverlay.style.width = '100%';
	objOverlay.style.height = '100%';
	objBody.insertBefore(objOverlay, objBody.firstChild);
	if (navigator.appName=="Microsoft Internet Explorer"){
		y=document.documentElement.clientHeight;
		objOverlay.style.height = y+'px';
		selects = document.getElementById("panel").getElementsByTagName('select');
			for(i = 0; i < selects.length; i++) {
				selects[i].style.visibility = 'hidden';
			}
		}
	if(titolo!=false){sezione.getElementsByTagName('h3')[0].innerHTML=titolo};
}
function closeavanzata(){
	document.getElementById("ricercavanzata").className="";
	var objBody = document.getElementsByTagName("body").item(0);
	objBody.removeChild(objBody.childNodes[0]);
		selects = document.getElementById("container").getElementsByTagName('select');
			for(i = 0; i < selects.length; i++) {
				selects[i].style.visibility = 'visible';
		}
}

/** ============ OVERLAY ============= */
/**
 * Richiamato per modificare lo stato della velina da "ricerca" a "caricamento"
 */
function setOverlayToLoading() {
	overlay.className = "map-loading";
	resizeOverlay();
}
/**
 * Richiamato per modificare lo stato della velina da "caricamento" a "ricerca"
 */
function setOverlayToSearch() {
	overlay.className = "map-overlay";
	resizeOverlay();
}
/**
 * Effettua il resize delal velina in base al proprio stato.
 */
function resizeOverlay() {
	if (overlay.className == "map-overlay") {
		overlay.style.top = ((parseInt(mappa.style.height) / 2) + 50) + "px";
		overlay.style.left = ((parseInt(mappa.style.width) / 2) - 50) + "px";	   
	} else {
		overlay.style.top = (mappa.offsetTop + 30) + "px";
		overlay.style.left = (parseInt(mappa.style.width) - 60) + "px";	   
	}
}
