var houseIcon = new google.maps.Icon(G_DEFAULT_ICON);
houseIcon.image = 'house.png';
houseIcon.iconSize = new google.maps.Size(30, 36);
houseIcon.iconAnchor = new google.maps.Point(5, 34);
houseIcon.infoWindowAnchor = new google.maps.Point(17, 1);
houseIcon.shadow = null;

function mapCivic(map, civic, error_callback)
{
    map.getContainer().style.display = 'none';
    var geocoder = new google.maps.ClientGeocoder();
    geocoder.setBaseCountryCode(civic.country);

    var displayCivicMap = function(response)
    {
        if (response && response.Status.code == 200)
        {
            map.setMapType(G_NORMAL_MAP);
            map.getContainer().style.display = 'block';
            map.checkResize();

            map.clearOverlays();
            var place = response.Placemark[0];
            var point = new google.maps.LatLng(place.Point.coordinates[1],
                                               place.Point.coordinates[0]);
            var houseMarker = new google.maps.Marker(point, { icon: houseIcon });
            shape = houseMarker;
            google.maps.Event.clearListeners(houseMarker);
            google.maps.Event.addListener(houseMarker, "click", function() {
                houseMarker.openInfoWindowHtml(civic.toString(true));
            });

            if (place.ExtendedData && place.ExtendedData.LatLonBox)
            {
                var box = place.ExtendedData.LatLonBox;
                var bounds = new google.maps.LatLngBounds(new google.maps.LatLng(box.south, box.west),
                                                          new google.maps.LatLng(box.north, box.east));
                map.setZoom(map.getBoundsZoomLevel(bounds));
            }
            else
            {
                map.setZoom(14);
            }
            map.setCenter(point);

            map.addOverlay(shape);
        }
        else if (error_callback)
        {
            error_callback('no map for', civic.toString(true) + ' (' + civic.toString() + ')');
        }
    };

    geocoder.getLocations(civic.toString(true), displayCivicMap);
}

function mapGeodetic(map, geodetic)
{
    map.setMapType(G_HYBRID_MAP);
    map.getContainer().style.display = 'block';
    map.checkResize();

    map.clearOverlays();
    var shape = geodetic.shape.toGMapShape();

    var zoom = map.getBoundsZoomLevel(shape.getBounds());
    map.setZoom(zoom - 1);
    map.setCenter(shape.getCentre());

    map.addOverlay(shape);
}
