﻿var markers = new Array();
var map = null;
var baseIcon = null;

function addMarker() {
    markers[arguments[1]] = arguments[0];
}

function openInfoWindowMarker() {
    GEvent.trigger(markers[arguments[0]], "click");
    if (map.getZoom() < 7) {
        map.setZoom(7);
    }
}

function initializeGoogleMap(latitude, longitude, zoom) {
    if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(latitude, longitude), zoom);
        map.setUIToDefault();

        // Create a base icon for all of our markers that specifies the
        // shadow, icon dimensions, etc.
        baseIcon = new GIcon(G_DEFAULT_ICON);
        baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
        baseIcon.iconSize = new GSize(20, 34);
        baseIcon.shadowSize = new GSize(37, 34);
        baseIcon.iconAnchor = new GPoint(9, 34);
        baseIcon.infoWindowAnchor = new GPoint(9, 2);
    }
}

function createMarker() {
    var numberIcon = new GIcon(baseIcon);

    var point = arguments[0];
    var id = arguments[1];
    var message = arguments[2];

    if (arguments[3]) {
        numberIcon.image = arguments[3];
        numberIcon.iconSize = new GSize(39 * 2, 34);
        numberIcon.shadow = "http://maps.google.com/mapfiles/arrowshadow.png";
        numberIcon.shadowSize = new GSize(39 * 2, 34);
    }
    else if (id) {
        numberIcon.image = "http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=" + id.toString() + "|00CC99|000000";
    }

    // Set up our GMarkerOptions object
    markerOptions = { icon: numberIcon };
    var marker = new GMarker(point, markerOptions);

    if (message) {
        GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(message); });
    }

    map.addOverlay(marker);

    addMarker(marker, id);

    return marker;
}