    var map;
    var baseIcon;
    var markers = new Array(); //Pointers to marker info window methods
    var markers_by_type = new Array();  //Pointers to arrays of GMarkers by type (for show/hide)
    var enabled_types = new Array(); //Array of marker types currently enabled
    var queueInfoWindow;
    var results = new Array();
    var restrict_to_center = false;
    var centerLat1 = 0;
    var centerLat2 = 0;
    var centerLng1 = 0;
    var centerLng2 = 0;

    // Creates a marker whose info window displays the caption
    function createMarker(map, latitude, longitude, html_caption, icon, id, marker_type, name) {
      type_enabled = 0;
      for (i=0; i < enabled_types.length; i++) {
        if (enabled_types[i] == marker_type) type_enabled = 1;
      }
      
      if (type_enabled) {
        inArray = 0;
        if (!markers_by_type[marker_type]) markers_by_type[marker_type] = new Array();
        if (id > 0 || id != '') {
          for (i=0; i < markers_by_type[marker_type].length; i++) {
             if (markers_by_type[marker_type][i]['id'] == id) inArray = 1;
          }
        }

        if (inArray == 0) {
          var point = new GPoint(longitude, latitude);
          var marker = new GMarker(point, icon);
          GEvent.addListener(marker, "click", markers[id] = function() {
            marker.openInfoWindowHtml(html_caption);
          });
          //GEvent.addListener(marker, "mouseover", markers[id]);
          map.addOverlay(marker);

          //Add the marker object to the array of arrays organized by type to allow show/hide functionality using checkboxes
          m = markers_by_type[marker_type][markers_by_type[marker_type].length] = new Array();
          m['marker'] = marker;
          m['id'] = id;
          m['name'] = name;
          m['info'] = markers[id];
          m['iconfile'] = icon.image;

          found = 0;
          for (i=0; i < results.length; i++) {
            if (results[i]['id'] == id) found = 1;
          }
          if (!found) results[results.length] = m;
        }
      }
    }

   function sortByName(a, b) {
     var x = a['name'].toLowerCase();
     var y = b['name'].toLowerCase();

     return ((x < y) ? -1 : ((x > y) ? 1 : 0));
   }

   function update_results() {
     iframe = document.getElementById('results');
     if (iframe) {
       results.sort(sortByName);

       str = '<p align="center"><b>Search Results</b></p>';
       for (i=0; i < results.length; i++) {
         str = str + '<div onmouseover="this.style.cursor=\'pointer\'; this.style.backgroundColor=\'#999999\';" onmouseout="this.style.backgroundColor=\'#eeeeee\'" onclick="parent.results['+i+'][\'info\']();"><img src="'+results[i]['iconfile']+'"> '+results[i]['name']+'</div>';
       }
       str = str + '</body></html>';
     
       iframe.contentWindow.document.body.innerHTML = str; 
     }
   }

   function enable_type(marker_type) {
     enabled_types[enabled_types.length] = marker_type;
     map_update();
   }

   function enable_types(marker_types) {
       for(enableTypesIndex=0; enableTypesIndex < marker_types.length; enableTypesIndex++) {
       	try {
           enable_type(marker_types[enableTypesIndex]);
	} catch (err) {alert(err);}
       }
   }

   function disable_type(marker_type) {
     newList = new Array();
     for (i=0; i < enabled_types.length; i++) {
       if (enabled_types[i] != marker_type) {
         newList[newList.length] = enabled_types[i];
       }
     }
     enabled_types = newList;

     if (markers_by_type[marker_type]) {
       for (i=0; i < markers_by_type[marker_type].length; i++) {
         map.removeOverlay(markers_by_type[marker_type][i]['marker']);
         tmp = results;
         results = new Array();
         for (j=0; j < tmp.length; j++) {
           if (tmp[j]['id'] != markers_by_type[marker_type][i]['id']) {
             results[results.length] = tmp[j];
           }             
         }
       }
     }

     markers_by_type[marker_type] = new Array();
     update_results();
   }

   function disable_types(marker_types) {
       for(disableTypesCounter=0; disableTypesCounter < marker_types.length; disableTypesCounter++) {
       	 try {
       	  disable_type(marker_types[disableTypesCounter]);
	 } catch(err) {alert(err);}
       }
   }

   function map_update() {
      bounds = map.getBounds();
      sw = bounds.getSouthWest();
      ne = bounds.getNorthEast();
      if (restrict_to_center) {
        if (centerLat1 == 0) {
          centerLat1 = sw.lat();
          centerLat2 = ne.lat();
          centerLng1 = sw.lng();
          centerLng2 = ne.lng();
        }
        lat1 = centerLat1;
        lat2 = centerLat2;
        lng1 = centerLng1;
        lng2 = centerLng2;
      } else {
        lat1 = sw.lat();
        lat2 = ne.lat();
        lng1 = sw.lng();
        lng2 = ne.lng();
      }
     
      new Ajax.Updater('ajaxdiv', '/txorails/public/misc/map_ajax?type=&lat1='+lat1+'&lat2='+lat2+'&lng1='+lng1+'&lng2='+lng2+'&maptype=lakes_zoom', {asynchronous:true, evalScripts:true});
    }

    function map_zoomin(overlay, point) {
      if (map.getZoom() < 12 && overlay) {
        map.setZoom(12);
      }
    }

    function map_init(latitude, longitude, zoom, restrict) {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map"));
        GEvent.addListener(map, "moveend", map_update);
          
        GEvent.addListener(map, "click", map_zoomin);
          
        map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());
        map.setCenter(new GLatLng(latitude, longitude), zoom);
        restrict_to_center = restrict;

 
        enabled_types[enabled_types.length] = 'L';

        icon_lake = new GIcon();
        icon_lake.iconSize = new GSize(25, 30);
        icon_lake.iconAnchor = new GPoint(12, 30);
        icon_lake.infoWindowAnchor = new GPoint(18, 3);
        icon_lake.image = "/images/icons/sail_lake_blue.png";

        icon_lake_rated = new GIcon();
        icon_lake_rated.iconSize = new GSize(25, 30);
        icon_lake_rated.iconAnchor = new GPoint(12, 30);
        icon_lake_rated.infoWindowAnchor = new GPoint(18, 3);
        icon_lake_rated.image = "/images/icons/sail_lake_red.png";
 
      }
    }

