﻿
function loadMap(location)
{
    if (GBrowserIsCompatible())
    {
        // A function to create the marker and set up the event window. This is from http://econym.org.uk/gmap/basic1.htm.
        // Don't try to unroll this function. It has to be here for the function closure.
        // Each instance of the function preserves the contents of a different instance
        // of the "marker" and "html" variables which will be needed later when the event triggers.    
        function createMarker(point, html) {
            var marker = new GMarker(point);
            GEvent.addListener(marker, "click", function() {
                marker.openInfoWindowHtml(html);
            });
            return marker;
        }

        var map = new GMap2(document.getElementById("map"));
        map.enableDoubleClickZoom();
        map.enableScrollWheelZoom();
        var point;
        var marker;
        switch (location)
        {
            case "HeadOffice":
                map.setCenter(new GLatLng(50.94917, -1.53839), 13);
                map.setUIToDefault();
                point = new GLatLng(50.94917, -1.53839);
                marker = createMarker(point, '<div style="width:200px">Deerfoot head office<br/>Mortimer\'s Park<br/>Ower<br/>Romsey<br/>Hampshire SO51 6AF<br/><b>023 8081 3001</b><\/div>')
                map.addOverlay(marker);
                break;
            case "City":
                map.setCenter(new GLatLng(51.51241, -0.08124), 13);
                map.setUIToDefault();
                point = new GLatLng(51.51241, -0.08124);
                marker = createMarker(point, '<div style="width:200px">Deerfoot City office<br/>10 Fenchurch Avenue<br/>London EC3M 5BN<br/><b>0203 178 4755</b><\/div>')
                map.addOverlay(marker);
                break;
            case "North":
                map.setCenter(new GLatLng(53.32743, -2.236), 13);
                map.setUIToDefault();
                point = new GLatLng(53.32743, -2.236);
                marker = createMarker(point, '<div style="width:200px">Deerfoot northern office<br/>Lowry House<br/>12 Kennerleys Lane<br/>Wilmslow<br/>Cheshire SK9 5EQ<br/><b>01625 418275</b><\/div>')
                map.addOverlay(marker);
                break;
            default: break;
        }
    }
    else
    {
        var mapDiv = document.getElementById("map");
        switch (location)
        {
            case "HeadOffice":
                mapDiv.innerHTML =
                    "<p><br/></p><p>Sorry, your browser is not capable of displaying the map for our head office.</p><p>Please call <b>023 8081 3001</b> for directions.</p>";
                break;
            case "City":
                mapDiv.innerHTML =
                    "<p><br/></p><p>Sorry, your browser is not capable of displaying the map for our City office.</p><p>Please call <b>0203 178 4755</b> for directions.</p>";
                break;
            case "North":
                mapDiv.innerHTML =
                    "<p><br/></p><p>Sorry, your browser is not capable of displaying the map for our northern office.</p><p>Please call <b>01625 418275</b> for directions.</p>";
                break;
            default: break;
        }
    }

}