
var descrizioneAzienda = "<p><strong>Areacom51</strong><br/>Via A. Diaz, 15 25062 - Concesio (Bs)<br/>Tel. 030 2000627<br/>E-Mail. <a href=\"mailto:info@areacom51.it\">info@areacom51.it</a></p>"

var map;
var gdir;
var trafficInfo = new GTrafficOverlay();
var geocoder = null;
var addressMarker;
var mArray = Array();


	/* Caricamento Mappa */
	function load() {

		if (GBrowserIsCompatible()) {
		
        	map = new GMap2(document.getElementById("map"));
			
			
			// Set Map Center
			map.setCenter(new GLatLng(45.591647, 10.224497), 13);
			
			
			// Set Map Controls
			map.addControl(new GMapTypeControl());
			map.addControl(new GLargeMapControl());
			map.enableDoubleClickZoom();
			
			
			// MiniMap
			var ovcontrol = new GOverviewMapControl(new GSize(120,120));
			map.addControl(ovcontrol);
			var ov_map = ovcontrol.getOverviewMap();
			GEvent.addListener(map, 'maptypechanged', function()
			{
				ov_map.setMapType(G_NORMAL_MAP);
			});
				
			
			// Pointers
			StdIcon = new GIcon();
			StdIcon.image = "immagini/standard.png";
			StdIcon.shadow = "immagini/shadow.png";
			StdIcon.iconSize = new GSize(20, 34);
			StdIcon.shadowSize = new GSize(37, 34);
			StdIcon.iconAnchor = new GPoint(9, 34);
			StdIcon.infoWindowAnchor = new GPoint(9, 2);
			StdIcon.infoShadowAnchor = new GPoint(18, 25);
			
			PersIcon = new GIcon();
			PersIcon.image = "immagini/green.png";
			PersIcon.shadow = "immagini/shadow.png";
			PersIcon.iconSize = new GSize(20, 34);
			PersIcon.shadowSize = new GSize(37, 34);
			PersIcon.iconAnchor = new GPoint(9, 34);
			PersIcon.infoWindowAnchor = new GPoint(9, 2);
			PersIcon.infoShadowAnchor = new GPoint(18, 25);
			
			RistIcon = new GIcon();
			RistIcon.image = "immagini/blue.png";
			RistIcon.shadow = "immagini/shadow.png";
			RistIcon.iconSize = new GSize(20, 34);
			RistIcon.shadowSize = new GSize(37, 34);
			RistIcon.iconAnchor = new GPoint(9, 34);
			RistIcon.infoWindowAnchor = new GPoint(9, 2);
			RistIcon.infoShadowAnchor = new GPoint(18, 25);
			
			
			// Itinerario
        	gdir = new GDirections(map, document.getElementById("directions"));
        	GEvent.addListener(gdir, "load", onGDirectionsLoad);
        	GEvent.addListener(gdir, "error", handleErrors);
			
			
			// Aggiunta Pointers alla mappa
			mArray.push('45.591647;10.224497;'+descrizioneAzienda+';0');
			
			addMarkers();
  	    	
  	    	
  	    }
	}
	
	
	// Creazione Itinerario
    function setDirections(fromAddress, toAddress, locale)
			{
      gdir.load("from: " + fromAddress + " to: " + toAddress,
				{ "locale": locale });
	    }
	    
	   
	// Gestione Errori di inserimento
    function handleErrors()
			{
			if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	    	alert("Indirizzo non trovato.\nError code: " + gdir.getStatus().code);

			else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
	    	alert("Impossibile processare la richiesta.\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("An unknown error occurred.");
		}
	
	
	// Handle Load Errors
	function onGDirectionsLoad()
		{
		} 

		
	// Add Pointers 
	function addMarkers()
		{
			
		if (mArray.length)
			{
			var bounds = new GLatLngBounds();
			for (n=0 ; n < mArray.length ; n++ )
				{
				var mData = mArray[n].split(';');
				var point = new GLatLng(mData[0], mData[1]);
				bounds.extend(point);
				var marker = createMarker(point, mData[2], mData[3]);
				map.addOverlay(marker);
				}
			}
		}		
		
	// PopUp	
	function createMarker(point, title, personal)
		{
		if (personal == 0) var icon = new GIcon(StdIcon);
		else if (personal == 1) var icon = new GIcon(PersIcon);
		else if (personal == 3)	var icon = new GIcon(RistIcon);
				
		var marker = new GMarker(point, icon);
		GEvent.addListener(marker, "click", function()
			{
			marker.openInfoWindowHtml('<div style="width:200px;height:60px"><b>' + title + '</b></div>');
			});
		return marker;
		}
		