/* 
 * The purpose of this JavaScript code is to:
 * 1. Determine if the browser is Google Maps capable
 * 2. Modify the div with ID to be visible
 * 3. Execute standard Google Maps code to display the location of the foodieplace
 */

// Map object
var map = null;

// Pin Object
var marker = null;

function loadMap(lat, lng, html) {
    // Mapping stuff
    if (GBrowserIsCompatible()) {
        // We sneek in a bit of JQuery to show the div
        $('#location_map').css({
                "width": "100%",
                "height": "350px",
                "border": "solid 1px black",
                "margin-bottom": "10px",
                "clear": "both"
        });

        map = new GMap2(document.getElementById("location_map"));
        // Point to centre map and to add pin marker and View Control
        var point = new GLatLng(lat,lng);
        map.setCenter(point, 11);
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        // Build standard marker html
        var markerHTML = "<div><h2>";
        markerHTML += html.title;
        markerHTML += "</h2>";
        // Body of marker html
        markerHTML += "<p>";
        for (line in html.address) {
            markerHTML += html.address[line];
            markerHTML += "<br/>";
        }
        markerHTML += "</p>";
        // Web address
        if (html.website != undefined && html.website.title != "") {
            markerHTML += '<a href="';
            markerHTML += html.website.href;
            markerHTML += '">';
            markerHTML += html.website.linktext;
            markerHTML += "</a>"
        }
        markerHTML += "</div>";
        // Plot the item
        marker = new GMarker(point);
        GEvent.addListener(marker, "click", function () {
            marker.openInfoWindowHtml(markerHTML);
        });
        map.addOverlay(marker);
    }
}

function unload() {
    // First, cleanupMarkers
    GEvent.clearListeners(marker, "click");
    // Now, the gMap stuff
    GUnload();
}



