﻿    var map = null;
    var zoomLevel = 5;
    var baseIcon = null;
    var gmarkers = [];
    var htmls = [];
    var curr_location = "alberta canada";
    
    function load() {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map"));
        map.enableScrollWheelZoom();
        setCenter(curr_location);
        map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());
        
        // Create a base icon for all of our markers that specifies the
        // shadow, icon dimensions, etc.
        baseIcon = new GIcon();
        baseIcon.image = "../../images/Mox_Gmaps_icon.png";
        baseIcon.shadow = "../../images/Mox_Gmaps_icon_shadow.png";
        baseIcon.iconSize = new GSize(43, 47);
        baseIcon.shadowSize = new GSize(43, 43);
        baseIcon.iconAnchor = new GPoint(18, 38);
        baseIcon.infoWindowAnchor = new GPoint(9, 2);
        baseIcon.infoShadowAnchor = new GPoint(18, 25);
        
        createMarker("calgary alberta canada", 0, "<div class=\"maps-info\">Calgary is home to a million people…and the world-famous Calgary Stampede.</div>");
        createMarker("edmonton alberta canada", 1, "<div class=\"maps-info\">Edmonton is Alberta’s major starting point for trips to the Arctic as well as the northern reaches of the Rockies.</div>");
      }
    }        
        
    function hideOverlays()
    {
        for (var i = 0; i < gmarkers.length; i++)
        {
            gmarkers[i].hide();
            gmarkers[i].closeInfoWindow();
        }
    }
    
    function setCenter(location)
    {
        var geocoder = new GClientGeocoder();
        geocoder.getLatLng(location, 
            function(point) {
                if (!point) {
                    alert(address +" not found");
                }
                else {
                    map.setCenter(point, zoomLevel);
                }
            }
        );
    }      
        
    // Creates a marker whose info window displays the location info
    function createMarker(address, index, html) {
      var geocoder = new GClientGeocoder();

      geocoder.getLatLng(address, 
        function(point) {
            if (!point) {
                //alert(address +" not found");
            }
            else {
                var marker = new GMarker(point);
                map.addOverlay(marker);

                htmls[index] = html;
                gmarkers[index] = marker;
                
                GEvent.addListener(marker, "click", function() {
                    marker.openInfoWindowHtml(html);          
                });
            }
        }
      );
    }  
    
    function openInfoWindow(i) {
        gmarkers[i].openInfoWindowHtml(htmls[i]);
    }