var itemGmap;

function centerThumb(img, width, height){
	if (img.width)
			imgwidth = img.width;
	else
			imgwidth=width;
	if (img.height)
			imgheight=img.height;
	else
			imgheight=height;
	moveleft = Math.round((width - imgwidth) / 2);
	if (moveleft>0)
			img.style.marginLeft= moveleft + "px";
	movetop = Math.round((height - imgheight) / 2);
	if (movetop>=0)
			img.style.marginTop= movetop + "px";
}

function loadMap(nPos, nLat, nLon, local){
	var prefix = "";
	var oGMap = new GMap2(document.getElementById("item_gmap_" + nPos));
	if (!oGMap)
		return(false);
	itemGmap = oGMap;

	oGMap.addControl(new GScaleControl());

	var oLatLng = new GLatLng(nLat, nLon);

	var nZoom = 15;

	var oIcon = new GIcon();
	if(oIcon){
		if (!local)	var prefix = "sitiagenzie/";
		oIcon.image = prefix + "img/streetMarker2.png";
		oIcon.iconSize = new GSize(15, 31);
		oIcon.iconAnchor = new GPoint(15, 31);
		oIcon.infoWindowAnchor = new GPoint(5, 1);
		nZoom = 15;
		
		oGMap.setCenter(oLatLng, nZoom);
		oGMap.savePosition();
		oGMap.addOverlay(new GMarker(oLatLng, oIcon));
	}
}

function changeStatusMap(operation){
	var oGMap = itemGmap;
	
	if(oGMap){
		switch (operation)
		{
			case "zoomIn":
				oGMap.zoomIn();
				break;

			case"zoomOut":
				oGMap.zoomOut();
				break;
			
			case "center":
                oGMap.returnToSavedPosition();
                break;

            case "satellite":
                oGMap.setMapType(G_SATELLITE_MAP);
                break;

            case "mappa":
	            oGMap.setMapType(G_NORMAL_MAP);
                break;

            case "ibrida":
                oGMap.setMapType(G_HYBRID_MAP);
                break;
		}
	}
}

function changeSelTab(father,child){
	var oTab = document.getElementById(father);
	if ( oTab )
	{
		var oChildTab = oTab.childNodes;
		if (oChildTab)
		{
			alert(oChildTab.length);
			for (var i=0; i < oChildTab.length ; i++){				
				if(oChildTab[i].id && oChildTab[i].id.indexOf(father + "_" + child) > -1 )
					oChildTab[i].className = "activelink";
				else 
					oChildTab[i].className = "";
			}
		}
	}
}

function miniMap(nPos, nLat, nLon, nAcc, local)
{
	var prefix = "";
	if (!local)	var prefix = "sitiagenzie/";
		
	var browser = navigator.userAgent.toLowerCase();
 	if (vslElIsVisible("item_map_" + nPos))
 	{
		if ( browser && (browser.indexOf("msie") > -1))
			vslCollapseEL("item_gmap_" + nPos, vslGetElementHeight("item_gmap_" + nPos), 1, -35, 25, null);
			
		vslCollapseEL("item_map_" + nPos, vslGetElementHeight("item_map_" + nPos), 1, -35, 25, function () {

		oEl = vslGetHTMLElement("item_map_" + nPos);
		if (oEl.style)
			oEl.style.height = "1px";

		oEl = vslGetHTMLElement("item_gmap_" + nPos);
		if (oEl.style){
			if ( browser && (browser.indexOf("msie")> -1))
				oEl.style.height = "1px";
			else 
				oEl.style.height = "200px";
		}

	 	var oElToolbarIcon = vslGetHTMLElement("mini_map_size_icon_" + nPos);
		var oElToolbarLabel = vslGetHTMLElement("mini_map_size_label_" + nPos);

	 	oElToolbarIcon.src = prefix + "img/Allarga.gif";
	 	oElToolbarLabel.innerHTML = "Allarga mappa";

	 	vslHEL("item_map_" + nPos);
	 	});
	 }
	 else
	 {
	 	vslSEL("item_map_" + nPos);
		vslSEL("item_gmap_" + nPos);

	 	vslCollapseEL("item_map_" + nPos, 1, 250, 20, 25, null);
		if ( browser && (browser.indexOf("msie") > -1))
			vslCollapseEL("item_gmap_" + nPos, 1, 200, 20, 25, null);
		else{
			oEl = vslGetHTMLElement("item_gmap_" + nPos);
			if (oEl.style)
				oEl.style.height = "200px";
		}
		
		var oGMap = new GMap2(document.getElementById("item_gmap_" + nPos));
		if (!oGMap)
		return(false);
	
		gvaMiniMaps[nPos] = oGMap;
		gvaMiniMapsLL[nPos] = new Array(nLat, nLon);
	
		oGMap.addControl(new GScaleControl());
	
		var oLatLng = new GLatLng(nLat, nLon);
		gvaMiniMapsLL[nPos] = oLatLng;
	
		var nZoom = 15;
	
		var oIcon = new GIcon();
		
	
		if (nAcc <= 5)
		{ oIcon.image = prefix + "img/cityMarker2.png";
			oIcon.iconSize = new GSize(15, 31);
			oIcon.iconAnchor = new GPoint(15, 31);
			oIcon.infoWindowAnchor = new GPoint(5, 1);
	
			nZoom = 14;
		}
		else if (nAcc <= 6)
		{ 
			oIcon.image = prefix + "img/streetMarker2.png";
			oIcon.iconSize = new GSize(15, 31);
			oIcon.iconAnchor = new GPoint(15, 31);
			oIcon.infoWindowAnchor = new GPoint(5, 1);
			nZoom = 15;
		}
		else
		{ 
			oIcon.image = prefix + "img/streetMarker2.png";
			oIcon.iconSize = new GSize(15, 31);
			oIcon.iconAnchor = new GPoint(15, 31);
			oIcon.infoWindowAnchor = new GPoint(5, 1);
			nZoom = 16;
		}
	
		oGMap.setCenter(oLatLng, nZoom);
		oGMap.savePosition();
		oGMap.addOverlay(new GMarker(oLatLng, oIcon));
	}
}

function centraMappa(nPos){
	setTimeout(function (){
		miniMapCtrl("center",nPos)
	},550);
}

function popupPrivacy(){
  window.open("http://www.immobiliare.it/casa/informazioni/politica-di-privacy.php","privacy","location=no,width=600,height=400,scrollbars=yes,resizable=yes,top=" + ((screen.height-400)/2) + ",left=" + ((screen.width-600)/2));
}
