
var gmap;
var gdir;
var addressmaker;
$( function() {
        loadmaps();

        $('#map_canvas').append('<div id="gmapborder-top"></div><div id="gmapborder-bottom"></div><div id="gmapborder-left"></div><div id="gmapborder-right"></div>');
        }
 );

var coord_office = [ 42.35542, -71.062939 ];

function loadmaps() {
    if (GBrowserIsCompatible()) {
        var ff_latlon = new GLatLng(coord_office[0], coord_office[1]);
        gmap = new GMap2(document.getElementById("map_canvas"));
        //gdir = new GDirections(gmap);
        gmap.setCenter(ff_latlon, 15);
        gmap.setUIToDefault();
        //gmap.addControl(new GSmallMapControl());
        //gmap.addControl(new GMapTypeControl());

        var ff_pin = new GLatLng(coord_office[0], coord_office[1]);
        var marker = new GMarker(ff_pin, getIcon('red'));
        var html = $('#ff_infowindow').html();
        gmap.addOverlay(marker);
        marker.bindInfoWindow(html);

        GEvent.trigger(marker, "click");  // show the infowindow


        //var geocoder = new GClientGeocoder();
        //geocoder.getLatLng('141 TREMONT STREET, BOSTON, MA', function(p) { console.log(p) } );
    }
}

function showparking() {
    var park_latlon = new GLatLng(42.35346,-71.067842);
    gmap.setCenter(park_latlon, 15);
    var icon = new GIcon();
    icon.image = "/images/parking.png";
    icon.iconSize = new GSize(32, 37);
    //icon.shadowSize = new GSize(22, 20);
    icon.iconAnchor = new GPoint(16, 36);
    icon.infoWindowAnchor = new GPoint(26, 3);
    var marker = new GMarker(park_latlon, icon);
    gmap.addOverlay(marker);
    marker.bindInfoWindow('<div class="mapinfo"><strong>Boston Common Parking Garage<br />Entrance</strong></div>');
    GEvent.trigger(marker, "click");  // show the infowindow
}

function getIcon(color) {
    if (!color) color = 'red';

    // Create our "tiny" marker icon
    var tinyIcon = new GIcon();
    tinyIcon.image = "http://labs.google.com/ridefinder/images/mm_20_"+color+".png";
    tinyIcon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
    tinyIcon.iconSize = new GSize(12, 20);
    tinyIcon.shadowSize = new GSize(22, 20);
    tinyIcon.iconAnchor = new GPoint(6, 20);
    tinyIcon.infoWindowAnchor = new GPoint(5, 1);
    return tinyIcon;
}



showNeighbor = function () {
    var latlon = $(this).attr('rel').split(',');
    var gpoint = new GLatLng(parseFloat(latlon[1]), parseFloat(latlon[0]));
    gmap.setCenter(gpoint, 15);

    if (!this.marker) {
        var marker = new GMarker(gpoint, getIcon('purple'));
        var html = $(this).next().html();
        gmap.addOverlay(marker);
        marker.bindInfoWindow(html);
        this.marker = marker;
    }
    GEvent.trigger(this.marker, "click");  // show the infowindow
    $(this).blur();
    return false;
}
    
function setDirections(fromAddress, toAddress, locale) {
    gdir.load("from: " + fromAddress + " to: " + toAddress, { "locale": locale });
}



    function handleErrors(){
        if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
            alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);
        else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
            alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);
        else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
            alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);
        else if (gdir.getStatus().code == G_GEO_BAD_KEY)
            alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);
        else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
            alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
        else alert("An unknown error occurred.");
    }

