	//<![CDATA[
	
	var Intermap = {};
		
	Intermap.statusLabels = {};
	Intermap.statusLabels.searching = '<span style="color: gray;">Ricerca dell\'indirizzo in corso...</span>';
	Intermap.statusLabels.addressNotFound = '<span style="color: red;">Indirizzo non trovato.</span>';

	Intermap.icons = {};
	Intermap.markers = [];
	
	window.onload = function () {
		
		load();
		
	}
	
	function load() {
	  if (GBrowserIsCompatible()) {
	    Intermap.map = new GMap2(document.getElementById("divIntermap"));
	    
	    Intermap.map.addMapType(G_PHYSICAL_MAP);
	    
	    Intermap.map.setMapType(G_PHYSICAL_MAP);
	    
	    Intermap.map.enableScrollWheelZoom()
	    Intermap.map.setCenter(new GLatLng(43.127048, 11.961365), 8);//ll=43.127048,11.961365
	    
	    Intermap.GLargeMapControl = new GLargeMapControl();
	    Intermap.GMapTypeControl = new GMapTypeControl();
	    
	    Intermap.map.addControl(Intermap.GLargeMapControl);
	    
		Intermap.map.addControl(Intermap.GMapTypeControl);

		Intermap.geoDecoder = new GClientGeocoder();
	    	  
	    /*  	    
		GEvent.addListener(Intermap.map,"click", function(overlay,point) { 

			setupMarker(point, null);
			
		});
		*/
		
	    Intermap.loadIcons();
	    
		if (Intermap.loadLocations) {
			
			Intermap.loadLocations();
			
		}

	  }
	}
	
	Intermap.loadIcons = function() {
		
		Intermap.icons.pin = new GIcon();
		Intermap.icons.pin.image = "../../img/gmaps/pinteresse.png";
		Intermap.icons.pin.iconSize = new GSize(26, 26);
		Intermap.icons.pin.shadowSize = new GSize(22, 20);
		Intermap.icons.pin.iconAnchor = new GPoint(12, 12);
		Intermap.icons.pin.infoWindowAnchor = new GPoint(21, 4);
		
		Intermap.icons.hotel = new GIcon();
		Intermap.icons.hotel.image = "../../img/gmaps/hotel.png";
		Intermap.icons.hotel.iconSize = new GSize(64, 64);
		Intermap.icons.hotel.shadowSize = new GSize(22, 20);
		Intermap.icons.hotel.iconAnchor = new GPoint(32, 32);
		Intermap.icons.hotel.infoWindowAnchor = new GPoint(55, 7);
		
		Intermap.icons.view = new GIcon();
		Intermap.icons.view.image = "../../img/gmaps/view.png";
		Intermap.icons.view.iconSize = new GSize(26, 26);
		Intermap.icons.view.shadowSize = new GSize(22, 20);
		Intermap.icons.view.iconAnchor = new GPoint(12, 12);
		Intermap.icons.view.infoWindowAnchor = new GPoint(21, 4);
		
	}
	
	function checkForSearchAddress(e) {
		
		var keycode;
		
		if(window.event) { //IE

			keycode = e.keyCode;
			
		} else if(e.which) { // Netscape/Firefox/Opera

			keycode = e.which;
			
		}
		
		if (keycode === 13) {
			
			searchAddress();
			
		}
		
	}
	
	function searchAddress() {
					
		var address = document.getElementById("txtAddressSearch").value;
		
		document.getElementById("lblStatus").innerHTML = Intermap.statusLabels.searching;
		
		Intermap.geoDecoder.getLocations(address,  function(result) {
		
			if (result.Status.code == G_GEO_SUCCESS) {
				
				document.getElementById("lblStatus").innerHTML = "";
				
				var lat = result.Placemark[0].Point.coordinates[1];
				var lng = result.Placemark[0].Point.coordinates[0];
				
				var point = new GLatLng(lat, lng);
				
				Intermap.map.setCenter(point, 15);
				
				if (Intermap.marker) {
					
					Intermap.marker.setLatLng(point);
					showAddress(result.Placemark[0].address);
					setCoords(result.Placemark[0].AddressDetails);
					
				} else {
				
					setupMarker(point, result.Placemark[0]);
					
				}
				
			} else {
				
				document.getElementById("lblStatus").innerHTML = Intermap.statusLabels.addressNotFound;
				
			}
		
		});
		
	}
	
	function setCoords(addressDetails) {
		
		document.getElementById("txtLongitude").value = Intermap.marker.getLatLng().lng();
		document.getElementById("txtLatitude").value = Intermap.marker.getLatLng().lat();
		
		if (addressDetails) {
								
			try {

				document.getElementById("txtCountry").value = addressDetails.Country.CountryNameCode;
				
			} catch (err) {
				
				document.getElementById("txtCountry").value = "";
				
			}
			
			try {

				document.getElementById("txtRegion").value = addressDetails.Country.AdministrativeArea.AdministrativeAreaName;
				
			} catch (err) {
				
				document.getElementById("txtRegion").value = "";
				
			}
			
			try {

				document.getElementById("txtTown").value = addressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.LocalityName;
				
			} catch (err) {
				
				document.getElementById("txtTown").value = "";
				
			}
			
			try {

				document.getElementById("txtCap").value = addressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.PostalCode.PostalCodeNumber;// (CAP)
				
			} catch (err) {
				
				document.getElementById("txtCap").value = "";
				
			}
						
			try {
				
				document.getElementById("txtAddress").value = addressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.Thoroughfare.ThoroughfareName;
				
			} catch (err) {
				
				document.getElementById("txtAddress").value = "";
				
			}
			
			Intermap.markerDraggingUserWarned = false;

		}
		
	}
		
	function addMarker(id, point, addressDetails, icon) {
							
//		/console.log(addressDetails);
		
		var intermapMarker = {};
		
		markerOptions = {draggable: false, icon:icon };
		
		var marker = new GMarker(point, markerOptions);

		var html = '<div class="bubble"><span class="bubble-title">' + addressDetails.title + '<br /></span><br />' + addressDetails.address + '<br />' + addressDetails.cap + ' - ' + addressDetails.town + '<br />' + addressDetails.region + ' ('+ addressDetails.country + ')</div>';

		if (addressDetails.id >= 0) {
			
			var lblReadMore;
			
			if (THE_LANGUAGE == 'it') {
			
				lblReadMore = 'Approfondimenti...';	
				
			} else {
				
				lblReadMore = 'Read more...';	
				
			}
			var link = (CONFIG_SEF_ENABLED) ? addressDetails.alias+'.htm' : 'index.php?option=com_map&task=view&id=' + addressDetails.id + '&lang='+ THE_LANGUAGE;
			html += '<div style="width: 250px; text-align: right; color: #111111;"><a href="'+link+'">' + lblReadMore + '</a></div>';
			
		}
		
		intermapMarker.html = html;
			
		GEvent.addListener(marker, "click", function() {
			//Intermap.map.closeInfoWindow();
			
			marker.openInfoWindowHtml(html);// + 
			//'<div style="width: 350px;">Quando si trascina il segnaposto manualmente, le informazioni relative all\'indirizzo della location non possono essere ottenute automaticamente.<br /><br />Assicurarsi che non ci siano incongruenze tra la posizione del segnaposto e l\'indirizzo specificato.</div>');
		});
		
		intermapMarker.marker = marker;
		intermapMarker.id = id;
					
		Intermap.markers.push(intermapMarker);
		
		Intermap.map.addOverlay(marker);
		
	}
	
	function showAddress(address) {
		
		Intermap.marker.openInfoWindowHtml("<br />" + address);
		
	}
	
	Intermap.highlightMarker = function(id) {
		
		for (var i = 0; i < Intermap.markers.length; ++i) {
			
			if (Intermap.markers[i].id == id) {
				
				Intermap.map.panTo(Intermap.markers[i].marker.getPoint());
				Intermap.markers[i].marker.openInfoWindowHtml(Intermap.markers[i].html);
				
			}
			
		}
		
	}
	
	function getUrlParameter(name) {
	
		name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
		
		var regexS = "[\\?&]"+name+"=([^&#]*)";
		var regex = new RegExp( regexS );
		var results = regex.exec( window.location.href );
		
		if( results == null )
			return "";
		else
			return results[1];
	}
	
	//]]>