
//<![CDATA[

		var cHost = window.location.hostname;
		var cPath = "/";

		var MyWebSite = "www.lacostaverde.it";
		if (cHost!=MyWebSite)
			cPath = GetLocalURL(MyWebSite+"/");

		var map; 

		var extStreetviewControl;
		var svOverlay;
		StreetViewControl.prototype = new GControl();

		var gdir;

		var WINDOW_HTML;

		var baseIcon1 = new GIcon(G_DEFAULT_ICON); 
		baseIcon1.iconSize=new GSize(12,20); 
     		baseIcon1.shadowSize=new GSize(22,20); 
     		baseIcon1.iconAnchor=new GPoint(6,20); 
     		baseIcon1.infoWindowAnchor=new GPoint(6,0); 

		var baseIcon2 = new GIcon(G_DEFAULT_ICON); 
		baseIcon2.iconSize=new GSize(32,37); 
     		baseIcon2.shadowSize=new GSize(40,30); 
     		baseIcon2.iconAnchor=new GPoint(16,37); 
     		baseIcon2.infoWindowAnchor=new GPoint(16,0); 

		var gicons = [];
		gicons["Comuni"] = new GIcon(baseIcon1,"../img/GoogleMaps/mm_20_red.png"); 
		gicons["Abitato"] = new GIcon(baseIcon1,"../img/GoogleMaps/mm_20_green.png"); 
		gicons["AbitatoMare"] = new GIcon(baseIcon1,"../img/GoogleMaps/mm_20_blue.png"); 
		gicons["Banche"] = new GIcon(baseIcon2,"../img/GoogleMaps2/bankeuro.png"); 
		gicons["Posta"] = new GIcon(baseIcon2,"../img/GoogleMaps2/postal.png");
		gicons["CarabPol"] = new GIcon(baseIcon2,"../img/GoogleMaps2/police.png");
		gicons["SMerc"] = new GIcon(baseIcon2,"../img/GoogleMaps2/supermarket.png"); 
		gicons["Aliment"] = new GIcon(baseIcon2,"../img/GoogleMaps2/convenience.png"); 
		gicons["Forno"] = new GIcon(baseIcon2,"../img/GoogleMaps2/bread.png"); 
		gicons["Pescherie"] = new GIcon(baseIcon2,"../img/GoogleMaps2/My-fishshop.gif"); 
		gicons["Distrib"] = new GIcon(baseIcon2,"../img/GoogleMaps2/gazstation.png"); 
		gicons["Farmacie"] = new GIcon(baseIcon2,"../img/GoogleMaps2/doctor.png"); 
		gicons["Ospedali"] = new GIcon(baseIcon2,"../img/GoogleMaps2/hospital.png"); 
		gicons["Spiagge"] = new GIcon(baseIcon2,"../img/GoogleMaps2/beach.png"); 
		gicons["Camping"] = new GIcon(baseIcon2,"../img/GoogleMaps2/campingsite.png"); 
		gicons["SostaCamper"] = new GIcon(baseIcon2,"../img/GoogleMaps2/camping.png"); 
		gicons["AreaCamper"] = new GIcon(baseIcon2,"../img/GoogleMaps2/camperarea.png"); 
		gicons["Hotel"] = new GIcon(baseIcon2,"../img/GoogleMaps2/hotel.png"); 
		gicons["BB"] = new GIcon(baseIcon2,"../img/GoogleMaps2/bedandbreakfast1.png"); 
		gicons["AgriT"] = new GIcon(baseIcon2,"../img/GoogleMaps2/My-farmHolidays.gif"); 
		gicons["Residence"] = new GIcon(baseIcon2,"../img/GoogleMaps2/bungalow.png"); 
		gicons["Ristoranti"] = new GIcon(baseIcon2,"../img/GoogleMaps2/restaurant.png"); 
		gicons["Panorama"] = new GIcon(baseIcon2,"../img/GoogleMaps2/panoramic.png"); 
		gicons["Miniere"] = new GIcon(baseIcon2,"../img/GoogleMaps2/mine.png"); 
		gicons["NaturalMonument"] = new GIcon(baseIcon2,"../img/GoogleMaps2/monument.png"); 
		gicons["Archeologia"] = new GIcon(baseIcon2,"../img/GoogleMaps2/ancientmonument.png"); 
		gicons["SitoInteresse"] = new GIcon(baseIcon2,"../img/GoogleMaps2/sight.png"); 
		gicons["Picnic"] = new GIcon(baseIcon2,"../img/GoogleMaps2/picnic.png"); 
		gicons["Cascata"] = new GIcon(baseIcon2,"../img/GoogleMaps2/waterfall.png"); 
		gicons["Pesca"] = new GIcon(baseIcon2,"../img/GoogleMaps2/fishing.png"); 
		gicons["Surf"] = new GIcon(baseIcon2,"../img/GoogleMaps2/windsurfing.png"); 
		gicons["Porto"] = new GIcon(baseIcon2,"../img/GoogleMaps2/sailboat-sport.png"); 
		gicons["Discesa"] = new GIcon(baseIcon2,"../img/GoogleMaps2/sailboat-sport.png"); 
		gicons["Parco-Tema"] = new GIcon(baseIcon2,"../img/GoogleMaps2/themepark.png"); 
		gicons["UscitaSS"] = new GIcon(baseIcon2,"../img/GoogleMaps2/down.png"); 
		gicons["Aeroporti"] = new GIcon(baseIcon2,"../img/GoogleMaps2/airport.png"); 
		gicons["Porti"] = new GIcon(baseIcon2,"../img/GoogleMaps2/port.png");

		var MyGmarker = [];
		MyGmarker["Comuni"] = [];
		MyGmarker["Abitato"] = [];
		MyGmarker["Banche"] = [];
		MyGmarker["Posta"] = [];
		MyGmarker["CarabPol"] = [];
		MyGmarker["Acquisti"] = [];
		MyGmarker["Distrib"] = [];
		MyGmarker["Farmacie"] = [];
		MyGmarker["Ospedali"] = [];
		MyGmarker["Spiagge"] = [];
		MyGmarker["Camping"] = [];
		MyGmarker["Hotel"] = [];
		MyGmarker["BB"] = []; 
		MyGmarker["AgriT"] = [];
		MyGmarker["Residence"] = [];
		MyGmarker["Ristoranti"] = [];
		MyGmarker["NatantiBarche"] = [];
		MyGmarker["SostaCamper"] = [];
		MyGmarker["AreaCamper"] = [];
		MyGmarker["Panorama"] = []; 
		MyGmarker["Miniere"] = []; 
		MyGmarker["Varie"] = []; 
		MyGmarker["Pesca"] = [];
		MyGmarker["Surf"] = [];
		MyGmarker["Diporto"] = [];
		MyGmarker["Stradali"] = [];
		MyGmarker["Aeroporti"] = [];
		MyGmarker["Porti"] = [];
		MyGmarker["Archeo"] = [];
		MyGmarker["Parco"] = [];
		MyGmarker["Museo"] = [];
		MyGmarker["Natura"] = [];

		var Colore = "#ff0000";
		var Size = 3;
		var Opacita = 1;

		var oLink = document.createElement("link") 
		oLink.href = cPath + "css/mappa-costa-verde.css"; 
		oLink.rel = "stylesheet"; 
		oLink.type = "text/css"; 
		document.body.appendChild(oLink); 

		function load() {

			if (GBrowserIsCompatible()) {

				//------------------- CREAZIONE DELLA MAPPA ------------------

				map = new GMap2(document.getElementById("map"));

				map.setCenter(new GLatLng(39.617000,8.57050), 10);
				map.setMapType(G_PHYSICAL_MAP);

				map.setUIToDefault();

				//map.addControl(new GMapTypeControl());
				//map.addControl(new GLargeMapControl3D(true)); 

                                map.enableContinuousZoom(); 
                                map.enableScrollWheelZoom(); 
                                map.enableDoubleClickZoom(); 
				map.enableGoogleBar();

				GEvent.addListener(map, "zoomend", chkZoom); 
				GEvent.addListener(map, "moveend", chkMove); 

				//-------------------- CREAZIONE STREETVIEW -------------------

				var opts = {
					size : new GSize(230, 230), 
					hidden :true,
					controlStatus : "MINI" 
				};
				extStreetviewControl = new ExtStreetviewControl(opts);
				map.addControl(extStreetviewControl);

				// aggiunge controllo button streetview
				map.addControl(new StreetViewControl());

				// posiziona pegman a coordinate 0,0 per simulare che non è attivo
				var pov = {yaw : 0,pitch : 0};
				var pos = new GLatLng(0, 0);
				extStreetviewControl.setLocationAndPOV(pos, pov);

				GEvent.addListener(extStreetviewControl.getMarker(), "dragstart", DragPegManStart);
				GEvent.addListener(extStreetviewControl.getMarker(), "dragend", DragPegManEnd);

				//----------------- CARICAMENTO DATI MARKER ------------------

				LoadDataXML('XML/administrative.xml');
				LoadDataXML('XML/Abitato.xml');
				LoadDataXML('XML/Servizi.xml');
				LoadDataXML('XML/Banche.xml');
				LoadDataXML('XML/Distrib.xml');
				LoadDataXML('XML/Acquisti.xml');
				LoadDataXML('XML/Farmacie.xml');
				LoadDataXML('XML/Ospedali.xml');
				LoadDataXML('XML/Hotel.xml');
				LoadDataXML('XML/Camping.xml');
				LoadDataXML('XML/SostaCamper.xml');
				LoadDataXML('XML/BB.xml');
				LoadDataXML('XML/AgriT.xml');
				LoadDataXML('XML/Residence.xml');
				LoadDataXML('XML/Ristoranti.xml');
				LoadDataXML('XML/Panorama.xml');
				LoadDataXML('XML/Miniere.xml');
				LoadDataXML('XML/Varie.xml');
				LoadDataXML('XML/spiagge.xml');
				LoadDataXML('XML/Pesca.xml');
				LoadDataXML('XML/Surf.xml');
				LoadDataXML('XML/Diporto.xml');
				LoadDataXML('XML/Stradali.xml');
				LoadDataXML('XML/Aeroporti.xml');
				LoadDataXML('XML/Porti.xml');

			}

		}

		//--------------------                      ------------------

		function LoadDataXML(nameFile) {

			GDownloadUrl( nameFile, function(data, responseCode) {

				var xml = GXml.parse(data);
				var markers = xml.documentElement.getElementsByTagName("marker");

				for (var i = 0; i < markers.length; i++) {

					var category = markers[i].getAttribute("category");
					var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),parseFloat(markers[i].getAttribute("lng")));
					var title = markers[i].getAttribute("title");
					var description = markers[i].getAttribute("description");
					var address = markers[i].getAttribute("address");
					var phone = markers[i].getAttribute("phone");
					var website = markers[i].getAttribute("website");
					var icon = markers[i].getAttribute("icon");
					var photo = markers[i].getAttribute("photo");
					var photogallery = markers[i].getAttribute("photogallery");

					var k = MyGmarker[category].length;
			
					MyGmarker[category][k] = createMarker(category, point, title, description, address, phone, website, icon, photo,photogallery)

				}

			});

		}

		//--------------------                      ------------------

		function chkZoom() { 

			czoomlevel = map.getZoom(); 
			cmaptype = map.getCurrentMapType(); 

			if (czoomlevel > 14) { 
				if (cmaptype == G_PHYSICAL_MAP) { 
					map.setMapType(G_SATELLITE_MAP); 
				} 
			}
			else if (czoomlevel <= 14) { 
				if (cmaptype == G_SATELLITE_MAP) { 
					map.setMapType(G_PHYSICAL_MAP); 
				} 
			}

		}

		function chkMove() { 

			if (extStreetviewControl.isHidden() == false)
			{
				var pov = {yaw : 0,pitch : 0};
				extStreetviewControl.setLocationAndPOV(map.getCenter(), pov);
			}

		}

		//------------------------------------------------------------
		// 		    FUNZIONI GESTIONE MARKER
		//------------------------------------------------------------

       		function createMarker(category, point, title, description, address, phone, website, icon, photo,photogallery) {

			MyTitle = title;
			Myicona = gicons[icon];

	    		var marker = new GMarker(point, { title: MyTitle, icon: Myicona });	 
		 
			var Myhtml = "";


			if (title != "#") {
				Myhtml = Myhtml + "<div class=text_title_mappa><p>" + title + "</p></div>";
			}
			if (photo != "#") {
				if (description != "#") {
					Myhtml = Myhtml + "<div class=text_descrphotos_mappa>"
					Myhtml = Myhtml + "<img class=photos_mappa src=" + photo + ">";
					Myhtml = Myhtml + "<p>" + description + "</p></div>";
				}else{
					Myhtml = Myhtml + "<div class=photos_mappa><img src=" + photo + "></div>";
				}
			}else{
				if (description != "#") {
					Myhtml = Myhtml + "<div class=text_descr_mappa><p>" + description + "</p></div>";
				}
			}
			if (address != "#") {
				Myhtml = Myhtml + "<div class=text_descr_mappa><p>" + address + "</p></div>";
			}
			if (phone != "#") {
				Myhtml = Myhtml + "<div class=text_descr_mappa><p>" + phone + "</p></div>";
			}
			if (website != "#") {
				Myhtml = Myhtml + "<div class=text_link><p>" + "<a href='" + website + "' target=_blank > Informazioni </a>" + "</p></div>";
			}

          		GEvent.addListener(marker, "click", function() {
				marker.openInfoWindowHtml('<div class="infoWin">' + Myhtml + '</div>');

	           	});

           		return marker;		

		}

		//--------------------                      ------------------

		function VisibilityMarkers(MrkName) {

			map.closeInfoWindow();

			if (document.getElementById(MrkName).checked==false) {
				for (var i = 0; i < MyGmarker[MrkName].length; i++) {
					map.removeOverlay(MyGmarker[MrkName][i]);
				}
			} else {
				for (var i = 0; i < MyGmarker[""+ MrkName +""].length; i++) {
					map.addOverlay(MyGmarker[MrkName][i]);
				}
			}

		}

		//------------------------------------------------------------
		// 	  	  FUNZIONI GESTIONE STREET-VIEW
		//------------------------------------------------------------

		function StreetViewControl() {
		}

		StreetViewControl.prototype.initialize = function(map) {

			var container = document.createElement("div");
 
			var StreetViewDiv = document.createElement("div");
			this.setButtonStyle_(StreetViewDiv);
			container.appendChild(StreetViewDiv);
			StreetViewDiv.appendChild(document.createTextNode("StreetView"));

			GEvent.addDomListener(StreetViewDiv, "click", function() {
				ActiveStreetView();
			});
 
			map.getContainer().appendChild(container);
			return container;
    		}
 
		// By default, the control will appear in the top left corner of the map with 7 pixels of padding.
    		StreetViewControl.prototype.getDefaultPosition = function() {
      			return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(253, 7));
    		}
 
		// Sets the proper CSS for the given button element.
		StreetViewControl.prototype.setButtonStyle_ = function(button) {
      			button.style.textDecoration = "none";
      			button.style.color = "#000000";
      			button.style.backgroundColor = "white";
      			button.style.font = "small Arial";
      			button.style.fontSize = "11px";
      			button.style.fontWeight = "normal";
      			button.style.border = "1px solid black";
      			button.style.padding = "2px";
      			button.style.marginBottom = "3px";
      			button.style.textAlign = "center";
      			button.style.width = "6em";
      			button.style.cursor = "pointer";
    		}

		function ActiveStreetView() {

			if (extStreetviewControl.isHidden() == true) {

				extStreetviewControl.getMarker().show();

				extStreetviewControl.show();
				var pov = {yaw : 0,pitch : 0};
				extStreetviewControl.setLocationAndPOV(map.getCenter(), pov);

			}
			else{

				// posiziona pegman a coordinate 0,0 per simulare che non è attivo
				var pov = {yaw : 0,pitch : 0};
				var pos = new GLatLng(0, 0);
				extStreetviewControl.setLocationAndPOV(pos, pov);

				extStreetviewControl.hide();

			}

		}

		function DragPegManStart() { 
			svOverlay = new GStreetviewOverlay(); 
			map.addOverlay(svOverlay); 
		} 

		function DragPegManEnd() { 
			map.removeOverlay(svOverlay);
		} 

		function changeLocationAndPOV (locationName) { 
			var pos = new GLatLng(svTable[locationName].lat, svTable[locationName].lng); 
			extStreetviewControl.setLocationAndPOV(pos, svTable[locationName].pov); 
		}  

		//------------------------------------------------------------
		// 		FUNZIONI GESTIONE PERCORSI SINGLE
		//------------------------------------------------------------

		//--------------------                      ------------------

		function ShowPercorso() { 

			var combo
			combo = document.getElementById('Partenza'); 
			var Partenza = combo.options[combo.selectedIndex].text;
			combo = document.getElementById('Arrivo'); 
			var Arrivo = combo.options[combo.selectedIndex].text;

			if ( Partenza != 'Selezionare Partenza' && Arrivo != 'Selezionare Arrivo' ) {

				if ( Partenza != Arrivo ) {

					Partenza = ChangeName(Partenza);
					Arrivo = ChangeName(Arrivo);

					if ( gdir != null ) {
						gdir.clear();
					}

					if (document.getElementById('Dettaglio').checked==false) {
						gdir = new GDirections(map, null);				
					}else{
						gdir = new GDirections(map, document.getElementById("directions"));
					}

					GEvent.addListener(gdir, "error", handleErrors2);
					GEvent.addListener(gdir, "addoverlay", AddOverlayDirection); 

					gdir.load("from: " + Partenza + " to: " + Arrivo, { "locale": "it_IT" });

				}else{
					alert("Partenza ed Arrivo coincido!\nIl percorso non viene elaborato.");
				}  

			}else{
				if ( Partenza == 'Selezionare Partenza' ) {
					alert("Partenza non impostato!\nIl percorso non viene elaborato.");
				}else if ( Arrivo == 'Selezionare Arrivo' ) {
					alert("Arrivo non impostato!\nIl percorso non viene elaborato.");
				}  
			}  

		}  

		function AddOverlayDirection() {

			var polyline = gdir.getPolyline();
			var bounds = polyline.getBounds();
			map.setCenter(bounds.getCenter(map), map.getBoundsZoomLevel(bounds));

		}  


		function ChangeDettaglio() {

			if ( gdir != null ) {
				ShowPercorso();
			}  

		}  

		function handleErrors2(){
			if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
				alert("Corrispondenza geografica non trovata per una delle posizioni indicate.\nError code: " + gdir.getStatus().code);
			else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
				alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);
			else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
				alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);
			else if (gdir.getStatus().code == G_GEO_BAD_KEY)
				alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);
			else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
				alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
			else alert("Errore sconosciuto.");
		}

		function ChangeName(Name) { 
			if (Name == 'Funtanazza') {
				return "Montevecchio Marina" + ", Sardegna";
			}else if (Name == 'Gutturu Flumini') {
				return "Marina di Arbus" + ", Sardegna";
			}else if (Name == 'Spiaggia di Piscinas') {
				return "Waypoint1@39.541928,8.449205";
			}else if (Name == 'Tunaria') {
				return "Porto Palma" + ", Sardegna";
			}else if (Name == 'Torre dei Corsari') {
				return "Torre di Flumentorgiu" + ", Sardegna";
			}else if (Name == 'Spiaggia di Scivu') {
				return "Waypoint1@39.496151,8.412931";
			}else if (Name == 'Arrivare da Nord con la SS 131') {
				return "Waypoint1@39.772395,8.660799";
			}else if (Name == 'Arrivare da Sud con la SS 131') {
				return "Waypoint1@39.559044,8.880440";
			}else if (Name == 'Arrivare da Sud con la SS 126') {
				return "Fluminimaggiore" + ", Sardegna";
			}else{
				return Name + ", Sardegna";
			}
		}

		//--------------------                      ------------------

		function apri_Foto(url) { 
			newin = window.open(url, 'titolo', 'scrollbars=no, resizable=no, width=800, height=600, status=no, location=no, menubar=no, toolbar=no');
		} 

		function GetLocalURL(MyWebSite){

			var path = document.location.href;
			path = path.replace(/%20/gi, " ");
			Pos = path.search(MyWebSite);

			//alert(Pos);

			path = path.substring(0,(Pos+MyWebSite.length));

			return path;

		}

//]]>

