﻿<!--//--><![CDATA[//><!--
    var gdir;
    
    function setDirections(fromAddress, toAddress, locale) {
        gdir.load("from: " + fromAddress + " to: " + toAddress,
            { "locale": locale });
    }

    function handleErrors() {
        if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
            alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);
        else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
            alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);

        else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
            alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);

        else if (gdir.getStatus().code == G_GEO_BAD_KEY)
            alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);

        else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
            alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);

        else alert("An unknown error occurred.");

    }

    function onGDirectionsLoad() {}
    
    function BuildDirBlock(index)
    {
        return "<br /><a href=\"#Directions\" onclick=\"ShowDirections('" + locationAddress[index] + "');\">Get Directions</a><br />";
    }
        
renderMap = function() {
    
    if (GBrowserIsCompatible()) {
    
        
        if (document.getElementById("list_ziegler_us") && locationCoords && locationCoords.length > 0) {

            var locationItems = document.getElementById("list_ziegler_us").getElementsByTagName("LI");
            
            var map = new GMap2(document.getElementById("map_canvas"));
            map.setCenter(new GLatLng(0,0),0);
            map.addControl(new GSmallMapControl());
            map.addControl(new GMapTypeControl());
            
            gdir = new GDirections(map, document.getElementById("directions"));
            GEvent.addListener(gdir, "load", onGDirectionsLoad);
            GEvent.addListener(gdir, "error", handleErrors);
            
            var bounds = new GLatLngBounds();

            // Create a base icon for all of our markers that specifies the
            // shadow, icon dimensions, etc.
            var baseIcon = new GIcon();
            baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
            baseIcon.iconSize = new GSize(20, 34);
            baseIcon.shadowSize = new GSize(37, 34);
            baseIcon.iconAnchor = new GPoint(9, 34);
            baseIcon.infoWindowAnchor = new GPoint(9, 2);
            baseIcon.infoShadowAnchor = new GPoint(18, 25);

            // Creates a marker whose info window displays the letter corresponding
            // to the given index.
            function createMarker(point, index, bubbleText) {

                // Set up our GMarkerOptions object
                var marker = new GMarker(point);

                GEvent.addListener(marker, "click", function() {
                    marker.openInfoWindowHtml(bubbleText);
                });
                return marker;
            }

            
            for (var i=0; i < locationCoords.length; i++) {

                var coords = locationCoords[i].split(",");
                
                var latLng = new GLatLng(coords[0],coords[1]);
                var marker = createMarker(latLng, i, locationItems[i].innerHTML.replace(/<script.*<\/script>/,"") + BuildDirBlock(i));
                map.addOverlay(marker);
                
                bounds.extend(marker.getPoint());

            }
            
            map.setZoom(map.getBoundsZoomLevel(bounds));
            map.setCenter(bounds.getCenter());
        
        }
        

    }
    
}

renderMap();

//--><!]]>
