/** 
 *  googlemap.js
 *
*/
DadMap = {

    map: null,
    mapEl: 'map',
    zoomLevel: 15,
    iconPoint: null,
    largeCentrePoint: null,
    smallCentrePoint: null,
    largeCentrePoint_Munich: null,
    smallCentrePoint_Munich: null,
    largeCentrePoint_Amsterdam: null,
    smallCentrePoint_Amsterdam: null,

    imageIcon: '/includes/img/pin-dad.png',
    imageIconShadow: '/includes/img/pin-dad-shadow.png',

    initMap: function(location) {
        if (GBrowserIsCompatible()) {
            DadMap.largeCentrePoint = new GLatLng(51.479981, -0.171466);
            DadMap.smallCentrePoint = new GLatLng(51.478981, -0.158366);
			DadMap.largeCentrePoint_Munich = new GLatLng(48.14216, 11.59395);
            DadMap.smallCentrePoint_Munich = new GLatLng(48.14050, 11.60750);
            DadMap.largeCentrePoint_Amsterdam = new GLatLng(52.364336, 4.88607);
            DadMap.smallCentrePoint_Amsterdam = new GLatLng(52.36230114820335, 4.8993659019470215);

            // Display the map, with some controls and set the initial location 
            DadMap.map = new GMap2(document.getElementById(DadMap.mapEl));

            DadMap.map.removeMapType(G_HYBRID_MAP);
            var mapTypeControl = new GMapTypeControl();
            var topRight = new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(10, 10));
            var bottomRight = new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(10, 10));
            DadMap.map.addControl(mapTypeControl, topRight);

            GEvent.addListener(DadMap.map, "dblclick", function() {
                DadMap.map.removeControl(mapTypeControl);
                DadMap.map.addControl(new GMapTypeControl(), bottomRight);
            });

            // set map center point
            switch (location.toLowerCase()) {
                case "munich":
                    DadMap.iconPoint = new GLatLng(48.14216, 11.59395);
                    DadMap.setSmallMapCentre_Munich();
                    $('.enlarge').click(function() { DadMap.setLargeMapCentre_Munich() });
                    $('.closeMap').click(function() { DadMap.setSmallMapCentre_Munich() });
                    break;
                case "amsterdam":
                    DadMap.iconPoint = new GLatLng(52.364336, 4.88607);
                    DadMap.setSmallMapCentre_Amsterdam();
                    $('.enlarge').click(function() { DadMap.setLargeMapCentre_Amsterdam() });
                    $('.closeMap').click(function() { DadMap.setSmallMapCentre_Amsterdam() });
                    break;
                default :
                    DadMap.iconPoint = new GLatLng(51.480981, -0.171866);
                    DadMap.setSmallMapCentre();
                    $('.enlarge').click(function() { DadMap.setLargeMapCentre() });
                    $('.closeMap').click(function() { DadMap.setSmallMapCentre() });
                    break;
            }

            DadMap.map.addControl(new GSmallMapControl());
            DadMap.map.addControl(new GOverviewMapControl());
            DadMap.map.enableScrollWheelZoom();

            // Create custom marker icon
            var icon = new GIcon();
            icon.image = DadMap.imageIcon;
            icon.shadow = DadMap.imageIconShadow;
            icon.iconSize = new GSize(73.0, 58.0);
            icon.shadowSize = new GSize(103.0, 58.0);
            icon.iconAnchor = new GPoint(36.0, 29.0);

            var marker = new GMarker(DadMap.iconPoint, icon);
            DadMap.map.addOverlay(marker);
        }
        else {
            // display a warning if the browser was not compatible
            //alert("Sorry, the Google Maps API is not compatible with this browser");				
        }
    },

    setMapCentre: function(point) {
        DadMap.map.setCenter(point, DadMap.zoomLevel);
    },

    setSmallMapCentre: function() {
        DadMap.setMapCentre(DadMap.smallCentrePoint);
    },

    setLargeMapCentre: function() {
        DadMap.setMapCentre(DadMap.largeCentrePoint);
    },
    setSmallMapCentre_Munich: function() {
        DadMap.setMapCentre(DadMap.smallCentrePoint_Munich);
    },

    setLargeMapCentre_Munich: function() {
        DadMap.setMapCentre(DadMap.largeCentrePoint_Munich);
    },
    setSmallMapCentre_Amsterdam: function() {
        DadMap.setMapCentre(DadMap.smallCentrePoint_Amsterdam);
    },

    setLargeMapCentre_Amsterdam: function() {
        DadMap.setMapCentre(DadMap.largeCentrePoint_Amsterdam);
    }
};
