function IdentifyPopup(map, title, contents, width, height, lat, lon) {
  //place popup at x,y
  
  this.map = map;
  this.width = width,
  this.height = height;
  this.title = title;
  this.bbox = map.viewportBBox;
  this.contentString = contents;

  var coords = map.getPixelFromLatLon(lat, lon);


  this.mapX = coords[0] - (width / 2);
  this.mapY = coords[1] - height;
  
  
  this.lat = lat;
  this.lon = lon;
  
  this.createIdentifyPopupHTML();
  
  var _this = this;
  this.map.setEvent('ondonemoving', function() {_this.map.centerLL = [_this.lon, _this.lat]; _this.map.setEvent('ondonemoving',null);});
}




IdentifyPopup.prototype.fillContentsAJAX = function(servletUrl, argString) {
  var _this = this;
  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());
}

IdentifyPopup.prototype.fillContents = function(contentsString) {
  this.content.innerHTML = contentsString;
  var llCorr = getElementsByClassName(this.content, 'align_coords');
  if (llCorr && llCorr[0]) {
    llCorr = llCorr[0].innerHTML;
    var ll = llCorr.split(',');
    if (ll[0] != 'null' && ll[1] != 'null') {
      this.lat = ll[0];
      this.lon = ll[1];
    }
  }
}







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.width/2);
  this.mapY = -1 * ((this.lat - bbox.ymax) / this.map.deg_px_y) - this.height;

  
  this.draw();
}


IdentifyPopup.prototype.createIdentifyPopupHTML = function() {
    var pu = document.createElement('div');
    pu.popupObject = this;
    pu.className = 'custom-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 html = '<img src="scrollable_map/images/blank.gif" style="width:200px;height:200px;position:absolute;top:0px;left:0px;" usemap="#popupmap"/>';
    html += '<map name="popupmap">';
    html += '<area id="imgarea1" style="cursor: default" shape="poly" coords="0,170,130,170,98,200,0,200,0,170" href="javascript://void(0)" onmousedown="map1._performAction(event); return false"/>';
    html += '<area id="imgarea2" style="cursor: default" shape="poly" coords="167,170,200,170,200,200,104,200,167,170" href="javascript://void(0)" onmousedown="map1._performAction(event); return false"/>';
    html += '</map>';

    this.pu.innerHTML = html;
  
    var _this = this;
    
    var cancel = document.createElement('img');
    cancel.className = 'popup-cancel';
    cancel.src = 'scrollable_map/images/cancel.png';
    cancel.map = this.map;
    cancel.onclick = function() {  
      _this.pu.popupObject.kill();
      return false;
    }
    this.cancel = cancel;
    
    var content = document.createElement('div');
    content.innerHTML = this.contentString;
    content.className = 'popup-content';
  
    this.content = content;
    
    
    this.pu.appendChild(this.content);
    
    this.pu.appendChild(this.cancel); 

    this.map.mapViewport.appendChild(this.pu);

    document.getElementById("imgarea1").map = this.map;    
    document.getElementById("imgarea2").map = this.map;    
    
    this.draw();
}




IdentifyPopup.prototype.moveBy = function(dx, dy) {

    this.mapY += dy;
    this.mapX += dx;

    this.draw();
}



IdentifyPopup.prototype.draw = function() {

      this.pu.style.top = this.mapY + 'px';
      this.pu.style.left = this.mapX + 'px';
    //avoid rendering problems
    if ((this.mapY + this.height - 20) < ((this.map.ydim - 2) * this.map.tileHeight) && this.mapY > 0) {
      this.content.style.overflow = 'auto';
      if ((this.mapX + this.width) < ((this.map.xdim - 2) * this.map.tileWidth) && this.mapX > 0) {
        this.content.style.overflow = 'auto';
      } else {
        this.content.style.overflow = 'hidden';
      }       
    } else {
      this.content.style.overflow = 'hidden';
    }      
    
}



IdentifyPopup.prototype.kill = function() {

  //this.map.parentMapObject.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;  
}