function IdentifyPopup(map, title, contents, width, height, lat, lon) {
  //place popup at x,y
  
  this.map = map;
  this.width = 225;
  this.height = 270;
  this.title = title;
  this.contentString = contents;

  var coords = map.getPixelFromLatLon(lat, lon);
  this.mapX = coords[0];
  this.mapY = coords[1];
  
  this.hlX = this.mapX;
  this.hlY = this.mapY;
  
  
  this.lat = lat;
  this.lon = lon;
	this.centerLat = lat;
	this.centerLon = lon;
  this.createIdentifyPopupHTML();
}




IdentifyPopup.prototype.fillContentsAJAX = function(servletUrl, argString, callback) {
  var _this = this;
  this.callback = callback;
  if (this.ar) this.ar.abort();
  this.ar = new AjaxRequest();
  this.ar.asyncRequest('GET', servletUrl, argString, function() {_this.ajaxCallback();});
}

IdentifyPopup.prototype.ajaxCallback = function() {
  this.fillContents(this.ar.getResponseText());
  this.callback();
}

IdentifyPopup.prototype.fillContents = function(contentsString) {
  this.content.innerHTML = contentsString;
  
  var pname = document.getElementById('pname');
  if (pname) {
    this.pmt.innerHTML = pname.value;
  }
  if (document.getElementById('popup-id') && !this.minmax.max)
    this.pu.style.backgroundColor = document.getElementById('popup-id').style.backgroundColor;  
}







IdentifyPopup.prototype.reposition = function() {
  //for use on zoom  recalculate x,y based on lat lon when pixel/degree ratios change
  //var cX = (curMap.degreesPerPixelX * mapCoords[0]) + curMap.viewportBBox.xmin;
  //var cY = curMap.viewportBBox.ymax - (curMap.degreesPerPixelY * mapCoords[1]);
  
  var bbox = this.map.getViewportBoundingBox();
  
  
  this.mapX = (this.lon - bbox.xmin) / this.map.deg_px_x;
  this.mapY = -1 * ((this.lat - bbox.ymax) / this.map.deg_px_y);


  this.hlX = (this.lon - bbox.xmin) / this.map.deg_px_x + 50;
  this.hlY = -1 * ((this.lat - bbox.ymax) / this.map.deg_px_y);
  
  this.draw();
}


IdentifyPopup.prototype.createIdentifyPopupHTML = function() {
    var pu = document.createElement('div');
    pu.popupObject = this;
    pu.className = 'popup';
    pu.oncontextmenu = function() { return false };
    pu.map = this.map;
        
    pu.style.top = this.mapY + "px";
    pu.style.left = this.mapX + "px";
        
    pu.style.width = this.width + "px";
    pu.style.height = this.height + "px";
    this.pu = pu;
    
    var _this = this;
    
    var pmt = document.createElement('div');
    pmt.className = 'popup-min-title';
    pmt.style.display = 'none';
    this.pmt = pmt;
    
    
    var highlight = document.createElement('div');
    highlight.className = 'popup-highlight';
    highlight.style.top = this.mapY - 6 + 'px';
    highlight.style.left = this.mapX - 6 + 'px';
    highlight.map = this.map;

    this.highlight = highlight;
    

    //var cancel = new Image();
    var cancel = document.createElement('img');
    cancel.src = 'scrollable_map/images/cancel.png';
    cancel.className = 'popup-cancel';
    cancel.map = this.map;
    cancel.onclick = function() {  
      _this.pu.popupObject.kill();
      if (_this.map.onidentifyclose) 
        _this.map.onidentifyclose();
      return false;
    }
    this.cancel = cancel;    

    
    var minmax = document.createElement('img');
    minmax.src = 'scrollable_map/images/minimize.PNG';
    minmax.max = true;
    minmax.className = 'popup-minmax';
    minmax.map = this.map;
    minmax.onclick = function() {  
      if (this.max) {
        this.max = false;
        this.src = 'scrollable_map/images/maximize.PNG';
        _this.pu.style.height = '20px';
        _this.pu.style.width = '150px';
        _this.content.style.display = 'none';
        _this.orig_height = _this.height;
        _this.height = 20;
        _this.orig_width = _this.width;
        _this.width = 150;
        _this.draw();    
        _this.pmt.style.display = 'block';
        if (document.getElementById('popup-id'))
          _this.pu.style.backgroundColor = document.getElementById('popup-id').style.backgroundColor;
      } else {
        this.max = true;
        this.src = 'scrollable_map/images/minimize.PNG';
        _this.height = _this.orig_height;
        _this.pu.style.height = _this.height + 'px';
        _this.width = _this.orig_width;
        _this.pu.style.width = _this.width + 'px';
        _this.draw();
        _this.pu.style.backgroundColor = '';
        _this.pmt.style.display = 'none';
        _this.content.style.display = 'block';

        if (_this.centerLat && _this.centerLon) {
          var coords = _this.map.getPixelFromLatLon(parseFloat(_this.centerLat), parseFloat(_this.centerLon));
          _this.map.animateMoveToPx(coords[0], coords[1]);
        }
      }
      return false;
    }
    this.minmax = minmax;     
    
    
    var nbsp = document.createElement('div');
    nbsp.innerHTML = '&nbsp;';
    nbsp.map = this.map;
    this.nbsp = nbsp;


    var content = document.createElement('div');
    content.innerHTML = this.contentString;
    content.className = 'popup-content';
  
    this.content = content;
    this.pu.appendChild(this.pmt);
    this.pu.appendChild(this.content);
    this.pu.appendChild(highlight);
    this.pu.appendChild(this.cancel);  
    this.pu.appendChild(this.minmax);  

    
    this.map.mapViewport.appendChild(this.highlight);
    this.map.mapViewport.appendChild(this.pu);
    this.draw();

}



IdentifyPopup.prototype.moveBy = function(dx, dy) {

    this.mapY += dy;
    this.mapX += dx;
    this.hlX += dx;
    this.hlY += dy;

    this.draw();
}



IdentifyPopup.prototype.draw = function() {
    this.highlight.style.top = this.hlY - 6 + 'px';
    this.highlight.style.left = this.hlX - 6 + 'px';

    if (this.minmax.max) {
			this.pu.style.top = (this.mapY-135) + 'px';
	    this.pu.style.left = (this.mapX+25) + 'px';   
    } else {
      this.pu.style.top = (this.map.tileHeight * (this.map.ydim - 2) - 22) + 'px';
      this.pu.style.left = (this.map.tileWidth * (this.map.xdim - 2) - 160) + 'px';    
    }
}




IdentifyPopup.prototype.kill = function() {

  this.map.mapViewport.removeChild(this.highlight);
  this.map.mapViewport.removeChild(this.pu);
  
  this.cancel.map = null;
  this.cancel.onclick = null;
  this.cancel = null;
  
  this.pu.map = null
  this.pu.onmouseover = null;
  this.pu = null;

  if (this.ar) {
    this.ar.abort();
    this.ar = null;
  }
  this.map.identifyPopup = null;  
}
