var geocoder = null;
var map = null;
var localSearch = null;

function youAreHere()
{
    geocoder.getLatLng(
        "Holborn Station",
        function(point) {
            if (point)
            {
                var marker = new GMarker(point);
                map.addOverlay(marker);
            }
        }
    );
}

function centreMap(latlng)
{
   map.setCenter(latlng, 16);
}

function markPoint(point)
{
    if (point)
    {
        map.setCenter(point, 16);
        map.clearOverlays();
        var marker = new GMarker(point);
        map.addOverlay(marker);
    }
}

function showAddress(address) {
    if (typeof timeout_click == "function")
    {
        timeout_click();
    }
    geocoder.getLatLng(
        address,
        function(point) {
            markPoint(point);
        }
    );
}

function showPostcode(postcode)
{
    localSearch.setSearchCompleteCallback(
        null,
        function()
        {
            if (localSearch.results[0])
            {
                var resultLat = localSearch.results[0].lat;
                var resultLng = localSearch.results[0].lng;
                var point = new GLatLng(resultLat,resultLng);
                markPoint(point);
            }
        });

    localSearch.execute(postcode + ", UK");
}


function loadMap()
{
    if (GBrowserIsCompatible())
    {
        map = new GMap2(document.getElementById("map_canvas"));
        localSearch = new GlocalSearch();
        geocoder = new GClientGeocoder();
        geocoder.setBaseCountryCode("uk");
        window.setTimeout(initMap, 50);
    }
}

