//gestione evento "onload"
if (window.addEventListener) {
	window.addEventListener("load", init, false);
} else if (window.attachEvent) {
	window.attachEvent("onload", init);
};

/*#.- .-.. . ... ... .- -. -.. .-. --- -.-. .- .. -- ..#*/
/* ]=====[]===[  Resize, Slide colonne  ]====[]=======[  */
/*#.- .-.. . ... ... .- -. -.. .-. --- -.-. .- .. -- ..#*/

var mappa, leftcolumn, leftcolumnlabel, bottompannel, bottompannelabel, footer;
var LeftCol = 280;
var BotLabHei = 14;
var BotHei = 80;
var LeftPix = 20;
var BotPix = 20;
var LeftVel = 10;
var BotVel = 10;
var footerHeight=20;
var headerHeight=50;

function init(){
	   mappa = document.getElementById("map");
	   mappa.style.marginLeft = LeftCol+"px";
	   leftcolumn = document.getElementById("leftcolumn");
	   leftcolumn.style.left = "0px";
	   leftcolumn.style.width = LeftCol+"px"
	   leftcolumnlabel = document.getElementById("leftcolumn_label");
	   leftcolumnlabel.style.left = LeftCol+"px";
	   bottompannel = document.getElementById("bottom");
	   bottompannel.style.bottom=footerHeight+"px";
	   bottompannel.style.height=BotHei+"px";
	   bottompannel.style.marginLeft = LeftCol+"px";
	   bottompannelabel = document.getElementById("bottom_label");
	   bottompannelabel.style.bottom = footerHeight+BotHei+"px";
	   bottompannelabel.style.marginLeft = LeftCol+"px";
	   document.getElementById('footer').style.bottom="0px";
	   headerHeight = document.getElementById('top').offsetHeight;
}
function resizemap(y){
	spaz=0;
	var offsetMap = ((parseInt(bottompannel.style.bottom) == footerHeight)?BotHei:0);
	// offsetMap += BotLabHei;
	mappa.style.height = y - spaz - offsetMap + "px";
	leftcolumn.style.height = y - spaz + "px";
	leftcolumnlabel.style.height = parseInt(mappa.style.height) + "px";
    if (xIE6) {leftcolumnlabel.getElementsByTagName("a")[0].style.height = parseInt(mappa.style.height) + "px";};
}

function slideLeft(){
	if (xIE6) {
		leftcolumn.style.left = -LeftCol + "px";
		mappa.style.marginLeft = "0px";
		leftcolumnlabel.style.left = "0px";	
		bottompannel.style.left = -LeftCol  + "px";
		bottompannelabel.style.left = -LeftCol + "px";
		
		// Notifies the map of a change of the size of its container.
		Gmap.checkResize();
	
		var link = leftcolumnlabel.getElementsByTagName("a")[0];
		link.href="javascript:slideRight()";
		link.className="slideright";
	} else {
		if(parseInt(leftcolumn.style.left) == -LeftCol){
			var link = leftcolumnlabel.getElementsByTagName("a")[0];
			link.href="javascript:slideRight()";
			link.className="slideright";
		}
		if(document.getElementById){
                if(parseInt(leftcolumn.style.left) <= 0 && parseInt(leftcolumn.style.left)>-LeftCol){
						leftcolumn.style.left = parseInt(leftcolumn.style.left) - LeftPix + "px";
						mappa.style.marginLeft = parseInt(mappa.style.marginLeft) - LeftPix + "px";
						leftcolumnlabel.style.left = parseInt(leftcolumnlabel.style.left) - LeftPix + "px";	
						bottompannel.style.left = parseInt(leftcolumn.style.left)  + "px";
	    				bottompannelabel.style.left = parseInt(leftcolumn.style.left)  + "px";
	    			  	// Notifies the map of a change of the size of its container.
	    			  	Gmap.checkResize();
	    			  	setTimeout("slideLeft()",LeftVel)
                }
        }
	}
}
function slideRight(){
	if (xIE6) {
		leftcolumn.style.left = "0px";
		mappa.style.marginLeft = LeftCol + "px";
		leftcolumnlabel.style.left = LeftCol + "px";
		bottompannel.style.left = "0px";
		bottompannelabel.style.left = "0px";
	
		// Notifies the map of a change of the size of its container.
		Gmap.checkResize();
		
		var link = leftcolumnlabel.getElementsByTagName("a")[0];
		link.href="javascript:slideLeft()";
		link.className="slideleft";
	} else {
		if(parseInt(leftcolumn.style.left) == 0){
			var link = leftcolumnlabel.getElementsByTagName("a")[0];
			link.href="javascript:slideLeft()";
			link.className="slideleft";
		}
		if(document.getElementById){
                if(parseInt(leftcolumn.style.left)>=-LeftCol && parseInt(leftcolumn.style.left)<0){
						leftcolumn.style.left = parseInt(leftcolumn.style.left) + LeftPix + "px";
						mappa.style.marginLeft = parseInt(mappa.style.marginLeft) + LeftPix + "px";
						leftcolumnlabel.style.left = parseInt(leftcolumnlabel.style.left) + LeftPix + "px";
						bottompannel.style.left = parseInt(leftcolumn.style.left)  + "px";
	   					bottompannelabel.style.left = parseInt(leftcolumn.style.left)  + "px";
              	  	    // Notifies the map of a change of the size of its container.
              	  	    Gmap.checkResize();
              	  	    setTimeout("slideRight()",LeftVel);
                }
        }
	}
}

function slideDown(){
	if (xIE6) {
		bottompannel.style.bottom = -BotHei + "px";
        bottompannelabel.style.bottom = footerHeight + "px";
        leftcolumnlabel.style.height = mappa.style.height = parseInt(mappa.style.height) + BotHei + "px";
		
        // Notifies the map of a change of the size of its container.
		Gmap.checkResize();
		
		var link = bottompannelabel.getElementsByTagName("a")[0];
		link.href="javascript:slideUp()";
		link.className="slideup";
	} else {
		// alert(bottompannel.style.bottom + " - " + footerHeight + " - " + (-BotHei+footerHeight))
		if(parseInt(bottompannel.style.bottom) == -BotHei+footerHeight){
			var link = bottompannelabel.getElementsByTagName("a")[0];
			link.href="javascript:slideUp()";
			link.className="slideup";
		}
		if(document.getElementById){
			if(parseInt(bottompannel.style.bottom) <= footerHeight && parseInt(bottompannel.style.bottom) > -BotHei+footerHeight){
	          bottompannel.style.bottom = parseInt( bottompannel.style.bottom) - BotPix + "px";
	          bottompannelabel.style.bottom = parseInt( bottompannelabel.style.bottom) - BotPix + "px";
			  mappa.style.height=parseInt(mappa.style.height) + BotPix + "px";
			  //leftcolumn.style.height =  parseInt(mappa.style.height) - BotPix + "px";
			  //leftcolumnlabel.style.height =  parseInt(mappa.style.height) - BotPix + "px";
			  leftcolumnlabel.style.height =  parseInt(mappa.style.height) + "px";
		  	  // Notifies the map of a change of the size of its container.
		  	  Gmap.checkResize();
			  setTimeout("slideDown()",BotVel);
	          }
	    }
	}
}
function slideUp(){
	if (xIE6) {
		bottompannel.style.bottom = footerHeight + "px";
        bottompannelabel.style.bottom = BotHei + footerHeight + "px";
        leftcolumnlabel.style.height = mappa.style.height = parseInt(mappa.style.height) - BotHei + "px";
		
        // Notifies the map of a change of the size of its container.
		Gmap.checkResize();

		var link = bottompannelabel.getElementsByTagName("a")[0];
		link.href="javascript:slideDown()";
		link.className="slidedown";
	} else {
		if(parseInt(bottompannel.style.bottom) == footerHeight){
			var link = bottompannelabel.getElementsByTagName("a")[0];
			link.href="javascript:slideDown()";
			link.className="slidedown";
		}
		if(document.getElementById){
			if(parseInt(bottompannel.style.bottom) >= -BotHei+footerHeight && parseInt(bottompannel.style.bottom) < footerHeight){
	          bottompannel.style.bottom = parseInt( bottompannel.style.bottom) + BotPix + "px";
	          bottompannelabel.style.bottom = parseInt( bottompannelabel.style.bottom) + BotPix + "px";
			  mappa.style.height = parseInt(mappa.style.height) - BotPix + "px";
			  //leftcolumn.style.height =  parseInt(mappa.style.height) - BotPix + "px";
			  //leftcolumnlabel.style.height =  parseInt(mappa.style.height) - BotPix + "px";
			  leftcolumnlabel.style.height =  parseInt(mappa.style.height) + "px";
		  	  // Notifies the map of a change of the size of its container.
		  	  Gmap.checkResize();
	          setTimeout("slideUp()",BotVel);
	          }
	     }
    }
}
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(){
	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 (xIE6){
		y=document.documentElement.clientHeight;
		objOverlay.style.height = y+'px';
		selects = document.getElementById("ricerca").getElementsByTagName('select');
			for(i = 0; i < selects.length; i++) {
				selects[i].style.visibility = 'hidden';
			}
		}
}
function closeavanzata(){
	document.getElementById("ricercavanzata").className="";
	var objBody = document.getElementsByTagName("body").item(0);
	objBody.removeChild(objBody.childNodes[0]);
	if (xIE6){
		selects = document.getElementById("ricerca").getElementsByTagName('select');
		for(i = 0; i < selects.length; i++) {
			selects[i].style.visibility = 'visible';
		}
	}
}