function drawMap(center, points) {
    if (!GBrowserIsCompatible()) {
        var map = document.getElementById('map');
        map.innerHTML = getMapErrorHtml();
        return;
    }

    //
    // Create the map
    //
    var map = null;
    mapE = document.getElementById("map");
    map = new GMap2(mapE);
    var cenpoint = new GLatLng(center[0], center[1]);
    map.setCenter(cenpoint, 14, G_HYBRID_MAP);
    // Set the map type and controls
    // map.setMapType(G_NORMAL_MAP);
    // map.setMapType(G_HYBRID_MAP);
    map.addControl(new GMapTypeControl());
    map.addControl(new GLargeMapControl());
    // map.enableScrollWheelZoom();

    //
    // Add markers
    // 
    for (var i = 0; i < points.length; i++) {
        var point = points[i];
        addMarker(map, point);
    }
}

function addMarker(map, point) {
    // Add the building marker overlay
    var icon = new GIcon();
    icon.image = "/images/maps/building_50.png";
    icon.shadow = "/images/maps/building_50_shadow.png";
    icon.iconSize = new GSize(50, 50);
    icon.shadowSize = new GSize(50, 50);
    icon.iconAnchor = new GPoint(16, 49);
    icon.infoWindowAnchor = new GPoint(25, 10);

    var latlng = new GLatLng(point.point[0], point.point[1]);
    var marker = new GMarker(latlng, {icon: icon, title: point.name, clickable: true, draggable: false});
    GEvent.addListener(marker, "click", function(data) {
        var params = {
            id: point.id, 
            submarket_id: point.submarket_id,
            year_built: point.year_built
        };
        $.get('/reports/building_map_html.php', params, function(data, textStatus) {
            marker.openInfoWindow(data);
        }, 'html');
    });
    map.addOverlay(marker);
}

function getMapErrorHtml() {
    var h = '<div style="text-align: center; padding: 20px">';
    h += '<h1>Your Browser is not compatible with the maps feature.</h1>';
    h += '<p>Please upgrade your browser to one compatible with Google Maps in order to view maps of this area.</p>';
    h += '</div>';
    return h;
}
