var infow;
function MyInfoWindow(marker, point, html) {
  this.point_ = point;
  this.html_ = html;
  this.marker = marker;
  if (this.marker.hintw)
    this.marker.hintw.Fix();
}
MyInfoWindow.prototype = new GOverlay();
MyInfoWindow.prototype.initialize = function(map) {
  var div = document.createElement("div");
  div.style.position = "absolute";
  div.innerHTML =
  '<div class="iwline1"><a onclick="MyInfoWindowClose()" style="z-index: 1000; position: relative"><img src="' + HTTPROOT + 'tmpl/img/map/w/closebutton.png" style="margin-right: 10px; cursor: pointer;"></a></div>'+
  '<div class="iwline2"><div style="position: relative">'+this.html_+'</div></div><div class="iwline3"></div>';
  map.getPane(G_MAP_MARKER_PANE).appendChild(div);
  this.map_ = map;
  this.div_ = div;

  //this.div_.onclick = function () { alert(1); window.event.cancelBubble = true; };
}
MyInfoWindow.prototype.remove = function() {
  this.div_.parentNode.removeChild(this.div_);
}
MyInfoWindow.prototype.copy = function() {
  return new MyInfoWindow(this.point_, this.html_);
}
MyInfoWindow.prototype.redraw = function(force) {
  if (!force) return;
  var c1 = this.map_.fromLatLngToDivPixel(this.point_);
  this.div_.style.width = "331px";
  this.div_.style.left = (c1.x - 16) + "px";
  this.div_.style.top = (c1.y - this.div_.offsetHeight - 16) + "px";

  if (this.div_.children)
    this.div_.children[1].style.height = "" + this.div_.children[1].offsetHeight + "px";
}
MyInfoWindow.prototype.PlaceWindow = function () {
  var sw = this.map_.fromLatLngToDivPixel(this.map_.getBounds().getSouthWest());
  var ne = this.map_.fromLatLngToDivPixel(this.map_.getBounds().getNorthEast());
  var newcenter = new GPoint(Math.round((ne.x + sw.x) / 2), Math.round((ne.y + sw.y) / 2));
  if (this.div_.offsetLeft + this.div_.offsetWidth - Math.max(ne.x, sw.x) > 0)
    newcenter.x += this.div_.offsetLeft + this.div_.offsetWidth - Math.max(ne.x, sw.x);
  else if (this.div_.offsetLeft < Math.min(ne.x, sw.x))
    newcenter.x += this.div_.offsetLeft - Math.min(ne.x, sw.x) - 3;
  if (this.div_.offsetTop + this.div_.offsetHeight - Math.max(ne.y, sw.y) > 0)
    newcenter.y += this.div_.offsetTop + this.div_.offsetHeight - Math.max(ne.y, sw.y);
  else if (this.div_.offsetTop < Math.min(ne.y, sw.y))
    newcenter.y += this.div_.offsetTop - Math.min(ne.y, sw.y) - 3;
  var cp = this.map_.fromDivPixelToLatLng(newcenter);
  map.panTo(cp);

  //this.inopen = 1;
  //this.ev = GEvent.bind(this.map_, "click", this, this.CloseIW);
}
MyInfoWindow.prototype.CloseIW = function () {
  ///if (this.inopen)
  //  this.inopen = 0;
  //else {
    if (this.marker.hintw)
      this.marker.hintw.UnFix();

    //GEvent.removeListener(this.ev);
    this.map_.removeOverlay(this);
  //}
}

function MyInfoWindowClose()
{
  if (infow) {
    infow.CloseIW();
    infow = null;
  }
}
