﻿// arrays to hold copies of the markers and html used by the side_bar
// because the function closure trick doesnt work there
var gmarkers = [];
var i = 0;
var bounds = new GLatLngBounds();
var map;
var iLat = 0;
var iLng = 0;
var iNomEtablissement = '';

function CreateMarkerAndPoint() {
    // add the points
    var point = new GLatLng(iLat, iLng);
    var marker = createMarker(point, iNomEtablissement);
    map.addOverlay(marker);
    bounds.extend(point);
    return marker;
}

// A function to create the marker and set up the event window
function createMarker(point, title) {
    // use a custom icon with letter A - Z
    //var letter = String.fromCharCode("A".charCodeAt(0) + i);
    var myIcon = new GIcon(G_DEFAULT_ICON, "/medias/communs/map/pushpin.png");
    myIcon.iconSize = new GSize(56, 43);
    myIcon.iconAnchor = new GPoint(30, 30);
    myIcon.shadow = "/medias/communs/map/shadow.png";
    myIcon.shadowSize = new GSize(56, 43);
    myIcon.printImage = "/medias/communs/map/pushpin.png";
    myIcon.mozPrintImage = "/medias/communs/map/pushpin.png";
    var marker = new GMarker(point, { icon: myIcon, title: title });

    // save the info we need to use later for the side_bar
    gmarkers[i] = marker;
    i++;
    return marker;
}

// This function picks up the click and opens the corresponding info window
function myclick(i) { GEvent.trigger(gmarkers[i], "click"); }

function initialize() {
    if (GBrowserIsCompatible()) {
        var mapDiv = document.getElementById("map_canvas");
        map = new GMap2(mapDiv);
        map.addControl(new GLargeMapControl3D());
        map.addControl(new GHierarchicalMapTypeControl());
        map.addMapType(G_PHYSICAL_MAP);
        map.addControl(new GScaleControl());
        var center = new GLatLng(iLat, iLng);
        map.setCenter(center, 10);
        var LogoDiv = mapDiv.firstChild.nextSibling
        var CopyrightDiv = LogoDiv.nextSibling;
        LogoDiv.className = "mapLogo"
        CopyrightDiv.className = "mapCopy";
    }
}

function initializeLatLngValues(lat, lng, NomEtablissement) {
    iLat = lat;
    iLng = lng;
    iNomEtablissement = NomEtablissement;
}
