 function addPopup(e) { // must be global function to support events.register
    var popup;
    popup = new EMS.Popup("map_popup", this.loc,
                              new OpenLayers.Size(180,60),
                              $A(this.names).join("<br/>"),
                              this.icon, true);
    this.map.addPopup(popup, true);
}


EMSMap = Class.create();


EMSMap.prototype = {
    initialize: function() {      
    },
    loadMapWithPOIs: function(elementName, locations) {
       this.map = new EMS.Services.Map(elementName);
        var bounds = new OpenLayers.Bounds();
        for (var index = 0; index < locations.size(); index++) {
          var loc = locations[index];
          var lonlat, icon, marker;
          lonlat = new EMS.LonLat(loc.longitude,loc.latitude);
          bounds.extend(lonlat);
          icon = EMS.Services.StandardIcons.poi(this.map.tilePath,"007FB2","385A70",loc.poi_number);
          marker = new OpenLayers.Marker(lonlat,icon);
          this.map.markersLayer.addMarker(marker);
          marker.events.register('mouseover',{names: loc.names, loc: lonlat, icon: icon, map: this.map}, addPopup);
        }
      var zoom = this.map.getZoomForExtent(bounds,false)-1;
      if (zoom>11) {zoom=11;}
      this.map.setCenter(bounds.getCenterLonLat(),zoom);
    },
    zoomMap: function(p1lo, p1la, p2lo, p2la) {
        var bounds = new OpenLayers.Bounds();
        bounds.extend(new EMS.LonLat(p1lo, p1la));
        bounds.extend(new EMS.LonLat(p2lo, p2la));
        this.map.zoomToExtent(bounds);
    },
    loadMap: function(elementName){        
        this.map = new EMS.Services.Map(elementName);
        this.zoomMap($('p1lo').value, $('p1la').value, $('p2lo').value, $('p2la').value);
    },
    resizeSelf: function() {
        this.map.updateSize();
    },
    saveMapBounds: function() {
        // search location is map area _either_ because 1) user is looking
        // at map, 2) user has done a search and they hit search against on
        // results page        
        if ($('search_location').value == '[map area]')  {
            bounds = this.map.calculateBounds().asWGS84(); 
            $('p1lo').value = bounds.left;
            $('p2lo').value = bounds.right;
            $('p1la').value = bounds.top;
            $('p2la').value = bounds.bottom;
        } else {
            $('p1lo').value = 0;
            $('p2lo').value = 0;
            $('p1la').value = 0;
            $('p2la').value = 0;
        }
    }
}

dropDownMap = new EMSMap();
pageMap = new EMSMap();

