   var g_fDebug = 1;
 

   var g_map;
   var g_directions;
 

   //-------------------------
   function Init()
   {
      g_map = LoadMap("DivMap", 47.60271, -122.33413, 13);
      
//      CreateMarkers();
   }
 
//   //-------------------------
//   function CreateMapMarker(map, sLat, sLon) 
//   {
//      var point = new GLatLng( parseFloat(sLat), parseFloat(sLon) );
//      var marker = new GMarker(point);
//      map.addOverlay(marker);
//    }
 
//   //-------------------------
//   function ClearOverlays(map)
//   {
//      map.clearOverlays();
//   }
 
//   //-------------------------
//   function PanToAsset(nArrayInx)
//   {
//      g_map.panTo( new GLatLng(g_rAssetLat[nArrayInx], g_rAssetLong[nArrayInx]) );
//   }
 
   //-------------------------
   function PanMapTo(map, sLat, sLon)
   {
      var point = new GLatLng( parseFloat(sLat), parseFloat(sLon) );
      map.panTo(point);
   }
 
   //-------------------------
   function LoadMap(mapDivName, lat, lon, zoom) 
   {
      if (GBrowserIsCompatible()) 
      {
         map = new GMap2(document.getElementById(mapDivName));
         
         // set the map type
//         map.setMapType(G_HYBRID_MAP);
         map.setMapType(G_NORMAL_MAP);
 
         // enable map options
         map.enableScrollWheelZoom();
         map.enableContinuousZoom();
 
         // set up the nav controls we want
         var topLeft = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(10,14));
         map.addControl(new GSmallZoomControl3D(), topLeft);
         
         // pick the map center
         var point = new GLatLng( lat, lon );
         map.setCenter(point, zoom);
 
         //----- set up the Aegis marker -----
         var objIcon = new GIcon();
         objIcon.image = "./images/aegisloc.png";
		 objIcon.shadow = "./images/aegislocshad.png";
         objIcon.iconSize = GSize(40, 63);
         objIcon.shadowSize = new GSize(63, 60);
         objIcon.iconAnchor = new GPoint(20, 62);
         objIcon.infoWindowAnchor = new GPoint(20, 62);
         // polygon that represents the clickable area of the icon -- used in FF
         objIcon.imageMap = new Array(0,20, 20,0, 40,20, 20,40, 0,20);  //(0,20, 20,0, 40,20, 20,40, 0,20);
         // 1% opaque image that lets you click the icon in IE when it is in the shadow of something else
         objIcon.transparent = "./images/aegislocX.png";
 
         var assetMarker = { icon:objIcon };
         var objMarker = new GMarker( new GLatLng(lat, lon), assetMarker );
         var objOverlay = map.addOverlay(objMarker);
 
         objMarker.bindInfoWindowHtml( GetInfoPopupHTML() );
 

         //----- connect the map to the click event -----
         GEvent.addListener(map,"click", 
            function(overlay, latlng) 
            {     
               if (latlng) 
               { 
                  var sHtml = GetDirectionsPopupHTML( latlng );
                  // sHtml = "The GPoint value is: " + map.fromLatLngToDivPixel(latlng) + " at zoom level " + map.getZoom();
                  map.openInfoWindow(latlng, sHtml);
               }
            }
         );
         
         
         return map;
      }
      else
      {
         alert("Sorry, the Google Maps API is not compatible with this browser");
      }
   }
 
   //-------------------------
   function GetInfoPopupHTML()
   {
      var sResponse;
      
      sResponse = 
            "<div class='styleInfoPopup'> " +
            "<b style='color: #800c00; font-size: 1.2em; text-decoration: none; line-height: 1.3em; font-weight: 300;'>Aegis Group, Inc.<br/>110 Cherry Street, Third Floor<br/>Seattle, WA 98104</b><br/><br/>" +
            "<a href='http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=110+Cherry+St,+Seattle,+WA+98104&sll=47.602648,-122.334207&sspn=0.0102,0.019119&ie=UTF8&z=16' target='_blank'>Map it on Google.</a> <br/>" +
            "<font> <br /> </font><br/>" +
            "</div>"
         ;
               
      return sResponse;
   }

   //-------------------------
   function GetDirectionsPopupHTML( /*GLatLng*/ latlng)
   {
      var sResponse;
      
      sScript = "ShowDirections(" + latlng.lat() + ", " + latlng.lng() + "); return false;" ;
      
      sResponse = 
            "<div class='styleInfoPopup'> " +
            "<a href='#' style='color: #800c00; font-size: 1.2em; text-decoration: none; line-height: 1.3em; font-weight: 300;' onclick='" + sScript + "'>Click to get directions <br/>from here to Aegis's office.</a> <br/>" +
            "</div>"
         ;
               
      return sResponse;
   }

   //-------------------------
      
	function overlayDirections()
 	{
      fromAddress =
        document.getElementById("street").value
        + " " + document.getElementById("city").value
        + " " + document.getElementById("state").options[document.getElementById("state").selectedIndex].value
        + " " + document.getElementById("zip").value;

		gdir.load("from: " + fromAddress + " to: " + toAddress, { "locale": language });
	}


 
   //-------------------------
   function ShowDirections(lat, lng)
   {
      //alert("ShowDirections: " + lat + ", " + lng);
     
      directionsPanel = document.getElementById("directions");
      if (g_directions)  g_directions.clear();
      g_directions = new GDirections(g_map, directionsPanel);
      g_directions.load("from: " + lat + ", " + lng + " to: 47.60271, -122.33413");
   }
  



/*
**
* Display error to user
*
*/
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.");
}

