// JavaScript Document
puntiLat = new Array();
puntiLng = new Array();
puntiDesc = new Array();
markers = new Array();

//--------------------------------------
//- PARAMETRI DA SETTARE PER OGNI SITO -
//--------------------------------------

// googleKey è la chiave di google, deve essere creata
// per il singolo dominio, tramite http://code.google.com/apis/maps/signup.html
googleKey = "ABQIAAAAb3x_VXogV2l8IkUGv6r6IxRZ1duTAAgz9GGv4k3vEe1vYo57NhRQzLPzhIb98Nz2k4s8uFeop6CY3g";

//nomeDivMappa èil nome del div in cui si vuole caricare la mappa
nomeDivMappa = "mappaGoogle";

//punti sulla mappa
// usare la funzione aggiungiPunto(latitudine, longitudine, descrizione) per ogni punto che si vuole aggiungere alla mappa, in descrizione si può usare html


//centroLat e centroLng sono le coordinate su cui si vuole centrare la mappa inizialmente e zoom è il livello di ingrandimento, va da 0 a 14 (0 molto distante, 14 molto vicino)
centroLat = 43.858505653159256;
centroLng = 10.497565269470215;
zoom = 13;


//--------------------------------------

//--------------------------------------
//-         CODICE PRINCIPALE          -
//--------------------------------------
// NON TOCCARE NULLA!!!!!

document.write('<script src="http://maps.google.com/maps?file=api&v=2&key='+googleKey+'" type="text/javascript"></script>');


function aggiungiPunto(lat, lng, descr){
    puntiLat.push(lat);
    puntiLng.push(lng);
    puntiDesc.push(descr);
}

function initEmbeddedMap() {
	//calcola il centro
	sumLat = 0;
	sumLng = 0;
	for(i=0; i<puntiLat.length; i++){
		sumLat = sumLat - (-1*puntiLat[i]);
		sumLng = sumLng - (-1*puntiLng[i]);
	}
	
	centroLat = sumLat / puntiLat.length;
	centroLng = sumLng / puntiLat.length;
	
	
	
	
    if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById(nomeDivMappa));
        map.addControl(new GSmallMapControl());
        map.addControl(new GMenuMapTypeControl());		
        map.enableScrollWheelZoom();
        
        var baseIcon = new GIcon(G_DEFAULT_ICON);
        baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
        baseIcon.iconSize = new GSize(56, 59);
        baseIcon.shadowSize = new GSize(0, 0);
        baseIcon.iconAnchor = new GPoint(9, 34);
        baseIcon.infoWindowAnchor = new GPoint(9, 2);
        
        
        var letteredIcon = new GIcon(baseIcon);        
        for(i=0; i<puntiLat.length; i++){
            letteredIcon.image = "http://www.gesam.it/immagini/common/lavoriInCorsoImg.png";
            markerOptions = { icon:letteredIcon };

            nuovoPunto = new GLatLng(puntiLat[i], puntiLng[i]);
            markers.push(new GMarker(nuovoPunto, markerOptions));
        }
        var centro = new GLatLng(centroLat, centroLng);
        map.setCenter(centro, zoom);
        for(i=0; i<markers.length; i++){
            map.addOverlay(markers[i]);	
            markers[i].bindInfoWindowHtml(puntiDesc[i]);
        }
    }
}
