﻿var map;
var geocoder;
var directions;

function Initialize()
{
    // Fire up google maps
    if (GBrowserIsCompatible())
    {
        // Initialize the Google maps control
        map = new GMap2(document.getElementById("map"),{ draggableCursor: "crosshair" });
        
        // Initialize the Google geocoder service (address to location)
        geocoder = new GClientGeocoder();

        // This is used for the 'snap to roads' feature
        directions = new GDirections();
        
        // Hook up our event handlers for things like clicking and dragging the map
        InitializeEventHandlers();
        
        // Set initial map position and zoom level
        map.setCenter(new GLatLng(37.09024, -95.712891), 2);
        map.setZoom(4);

        // Enable zooming by using scroll wheel, and double clicking.
        // Enable the continuous zoom feature, too. (select browsers only)
        map.enableScrollWheelZoom();
        map.enableDoubleClickZoom();
        map.enableContinuousZoom(); 
        
        // Add the topo map        
        map.addMapType(G_PHYSICAL_MAP);
        
        // Add controls to the map
        map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());
        SwitchUnitOfMeasure(EnglishUnits);
    }
    
    // Call this so we have a default unit type selected and know that the radio button matches the value in UnitOfMeasure
    SwitchUnitOfMeasure(EnglishUnits);
    
    // Set up the top menu that's above the map
    InitializeTopMenu();
    
    // Initialize the distance display
    UpdateDistanceDisplay();
    
    // Initialize the "snap to road" feature
    InitializeSnapToRoad();

    // We need to highlight the selected icon for our map markers menu    
    RefreshMapMarkersMenu();
    
    // We will show markers by default
    SetShowMapMarkers(true);
    SetShowDistanceMarkers(false); // but not distance markers
    
    // Fetch a list of the user's saved maps from the server
    RefreshListOfSavedMaps();
}
