/*  Minube Info Window
 */ 
 
function InfoWindow(html, width, height, marker) {
  this.marker_ = marker;
  this.html_ = html;
  this.width_ = width;
  this.height_ = height;
} 

InfoWindow.prototype = new GOverlay();

InfoWindow.prototype.initialize = function(map) {  
  this.map_ = map;
  
  var container = document.createElement('div');
  container.style.display = 'none';
  
  var outside_container = document.createElement('div');
  outside_container.style.display = 'none';
  
  var map_container = map.getPane(G_MAP_FLOAT_PANE).parentNode.parentNode.parentNode.parentNode.parentNode;  
  
  map_container.appendChild(outside_container);    
  map.getPane(G_MAP_FLOAT_PANE).appendChild(container);
    
  this.map_container_ = map_container;  
  this.container_ = container;
  this.outside_container_ = outside_container;  
} 

InfoWindow.prototype.remove = function() {
  this.container_.parentNode.removeChild(this.container_);
  this.map_container_.removeChild(this.outside_container_);
}

InfoWindow.prototype.copy = function() {
  return new InfoWindow(this.marker_, this.html_, this.width_);
}

InfoWindow.prototype.redraw = function(force) {
  if(!force) return;
  
  //content div

  var contentWidth = this.width_;
  var contentHeight = this.height_;
  var content = document.createElement('div');
  content.innerHTML = this.html_;
  content.style.font = '10px verdana';
  content.style.margin = '0';
  content.style.padding = '0';
  content.style.border = '0';
  content.style.width = 'auto';
  content.style.visibility = 'hidden'; //make it invisible for now
  content.style.position = 'absolute';
  content.style.background = 'transparent';  
  content.style.visibility = "visible";
  content.style.width = contentWidth + 'px';
  content.style.height = contentHeight + 'px';
  
  //add any event handlers like the close box
  
  var closeButton = $(content).down('#closeButton');
  if (closeButton) {
	  GEvent.addDomListener(closeButton, 'click', (function() {
	    this.map_.removeOverlay(this);
	    this.map_.activeInfoWindow = null;
	  }).bind(this));  	
  }
  
  //get the X,Y pixel location of the marker
  var pixelLocation = this.map_.fromLatLngToDivPixel(this.marker_.getPoint());
  
  //position the container div for the window
  this.container_.style.position = 'absolute';
  this.container_.style.left = (pixelLocation.x - 62) + "px";
  this.container_.style.top = (pixelLocation.y
    - contentHeight
    + 0 
    - this.marker_.getIcon().iconSize.height
  ) + "px";
  this.container_.style.border = '0';
  this.container_.style.margin = '0';
  this.container_.style.padding ='0';
  this.container_.style.display = 'block';
    
  
  var cPos = Position.cumulativeOffset(this.container_);
  var ocPos = Position.cumulativeOffset(this.outside_container_.parentNode);

  this.outside_container_.style.position = 'absolute';
  this.outside_container_.style.left = cPos[0] - ocPos[0] + "px";
  this.outside_container_.style.top = cPos[1] - ocPos[1] + "px";
  this.outside_container_.style.border = '0';
  this.outside_container_.style.margin = '0';
  this.outside_container_.style.padding ='0';
  this.outside_container_.style.display = 'block';
  this.outside_container_.style.zIndex = 20000;
  
  //append the styled info window to the container
  $(this.outside_container_).immediateDescendants().invoke('remove');
  //this.container_.appendChild(content.cloneNode(true));
  this.outside_container_.appendChild(content);  
}




