
//***************** DEFINITION DES IMAGES DE MARQUEURS ************************
// Marqueur rouge
var redIcon = new GIcon(G_DEFAULT_ICON);
redIcon.image = "/extension/crtpic_tourisme_handicap/design/tourisme_handicap/images/GMap_Actu.gif";
//redIcon.shadow = "";
redIcon.iconSize = new GSize(21, 26);
//redicon.shadowSize = new GSize(20,22);
redMarkerOptions = {icon:redIcon};

// Marqueur destination
var destination_icon = new GIcon(G_DEFAULT_ICON);
destination_icon.image = "/extension/site_generique/design/site_generique/images/google_maps/picto_destination.png";
destination_icon.shadow = "/extension/site_generique/design/site_generique/images/google_maps/ombre.png";
destination_icon.iconSize = new GSize(42, 27);
destination_icon.shadowSize = new GSize(42, 27);
destination_iconMarkerOptions = {icon:destination_icon};

var offre_icon = new GIcon(G_DEFAULT_ICON);
offre_icon.image = "/extension/site_generique/design/site_generique/images/google_maps/picto_offre.png";
offre_icon.shadow = "/extension/site_generique/design/site_generique/images/google_maps/ombre.png";
offre_icon.iconSize = new GSize(42, 27);
offre_icon.shadowSize = new GSize(42, 27);
offre_iconMarkerOptions = {icon:offre_icon};

var listeMaps = Array();
//***************** FONCTIONS GOOGLE MAPS ***********************************

/**
 * Cette fonction créer un nouveau marqueur google map et le renvoie
 * lat, lng : les coordonnées du marqueur
 * info : le texte à afficher dans la bulle lors d'un clic.
 * Si info = null alors l'icone ne comportera pas de description
 * bounds
 * (optionnel) icon : une image pour redéfinir l'affichage du marqueur
 */
function createMarker( lat, lng, info, bounds, icon)
{
    var point = new GLatLng(lat, lng);
    var marker = new GMarker( point, icon );
    
    if(info != null)
    {
        GEvent.addListener(marker, "click", function() {
            marker.openInfoWindowHtml(info);
        });
    }
    if (bounds)
    {
        bounds.extend(point);
    }
    return marker;      
}

/**
 * Cette fonction affiche une carte google maps dans un bloc
 * blockId : L'id du block dans lequel insérer la map
 * datas : Un tableau multidimensionnel contenant la liste des points
 * à afficher ainsi que leurs options. Exemple :
 *          data[i] = Array(
 *                      "latitude" => 33.3333
 *                      "longitude" => 22.22222
 *                      "icon" => "blue"
 *                      "contentobject_id" => 135
 *                  )
 * zoom : le niveau de zoom de la carte
 * center : le point sur lequel centrer la map Ex: Array(33.333, 22.2222)
 * display_info : booleen indiquant si on affiche ou non la description des
 * puces lorsque l'on clique dessus
 */
function displayMap(blockId, datas, zoom, center, display_info){
    
    var map = new GMap2(document.getElementById(blockId));
    map.addControl(new GSmallMapControl());
    
    map.setCenter(new GLatLng(center[0],center[1]), zoom);
    var bounds = new GLatLngBounds();
    map.setMapType(G_NORMAL_MAP);
    
    
    var index = 1;
    for(i=0; i < datas.length; i++)
    {
        var data = datas[i];
        
        // On récupère la description de notre point
        var latitude = data["latitude"];
        var longitude = data["longitude"];
        var icon = eval(data["icon"] + 'MarkerOptions');
        var contentobject_id = data["contentobject_id"];
        var text = document.getElementById('location_' + contentobject_id).innerHTML;
        
        if(display_info == false)
        {
            text = null;
        }
        
        // On ajoute le point sur la carte
        map.addOverlay(createMarker(latitude, longitude, text, bounds, icon));
    }
}


var gmapExistingOnload = null;
// Affichage de la carte :
if (window.onload)
{
    //Hang on to any existing onload function.
    gmapsExistingOnload = window.onload;
}

window.onload=function(ev){
    //Run any onload that we found.
    if (gmapExistingOnload)
    {
        gmapExistingOnload(ev);
    }
    if (GBrowserIsCompatible())
    {
        for(var j=0; j<listeMaps.length; j++)
        {
            var tab = listeMaps[j];
            displayMap(tab[0], tab[1], tab[2], tab[3], tab[4]);
        }
    }
}







