// $Id$

/**
 * Google Maps API functionality.
 */

// custom variables
var _mapDivId = 'map-canvas';
var _startCoords = new GLatLng(52.053550, 4.494320);
var _zoomLevel = 13;
var _address = '';
var _coords = [52.046910, 4.503010];
var _infoText = '';

// ------- std. GoogleMaps code ------------------------------------------------
// don't edit below this line unless you're extending functionality
// -----------------------------------------------------------------------------
var map = null;
var geocoder = null;

function initialize() {
    if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById(_mapDivId));
        map.setCenter(_startCoords, _zoomLevel);
        map.addControl(new GSmallMapControl());
        geocoder = new GClientGeocoder();
        if (_address.length) {
            showAddress(_address);
        }
        else if (_coords) {
            showCoordinates(_coords);
        }
    }
}

function showAddress(address) {
    if (geocoder) {
        geocoder.getLatLng(
            address,
            function(point) {
                if (!point) {
                    alert(address + " not found");
                } else {
                    map.setCenter(point, _zoomLevel);
                    var marker = new GMarker(point);
                    map.addOverlay(marker);
                    if (_infoText != '') {
                        marker.openInfoWindowHtml(_infoText);
                    }
                }
            }
        );
    }
}

function showCoordinates(coords) {
    var point = new GLatLng(coords[0], coords[1]);
    if (!point) {
        alert(address + " not found");
    } else {
        map.setCenter(point, _zoomLevel);
        var marker = new GMarker(point);
        map.addOverlay(marker);
        if (_infoText != '') {
            marker.openInfoWindowHtml(_infoText);
        }
    }
}
