var EnhancedGControl = Base.extend();
EnhancedGControl.prototype.extend(GControl.prototype);

var GInfoBoxControl = EnhancedGControl.extend({
  constructor: function (printable,selectable) {
    //this.base(printable,selectable);
    this.shown = false;
    this._printable = printable;
    this._selectable = selectable;
    //this.setOpacity(0.90);
    this.style = {};
    this.style.backgroundColor = "#000000";
    this.style.color = "#EEEEEE";
    this.style.display = "none";
    this.style["-mozBorderRadiusTopRight"] = "11px";
    this.style["borderRadiusTopLeft"] = "11px";
    this.style.padding="5px 10px";
    this.style.border="2px solid #222222";
  },

  setOpts: function(opts) {
    for ( var i in opts ) {
      this[i] = opts[i];  
    }
  },

  setOpacity: function(opacity) {
    if ( typeof(this.dom) != "undefined" ) {
      this.dom.style['opacity'] = opacity;
      this.dom.style['mozOpacity'] = opacity;
      this.dom.style['khtmlOpacity'] = opacity;
    }
    if ( typeof(this.style) == "undefined" ) this.style = {};
    this.style['opacity'] = opacity;
    this.style['mozOpacity'] = opacity;
    this.style['khtmlOpacity'] = opacity;
  },

  init: function() {
  },

  initialize: function(map) {
    var wrapper = document.createElement("div");

    wrapper.className = "infobox";
    if ( typeof(this.style) != "undefined" ) {
      for ( var i in this.style ) {
        wrapper.style[i] = this.style[i];
      }
    }
    this.shown = false;

    var closediv = document.createElement("div");
    closediv.className="closebutton";
    closediv.style["position"] = "absolute";
    closediv.style["float"] = "right";
    closediv.style["top"] = "7px";
    closediv.style["color"] = "#FFFFFF";
    closediv.style["right"] = "6px";
    closediv.style["fontWeight"] = "bold";
    closediv.style["backgroundColor"] = "#222222";
    closediv.style["fontSize"] = "15px";
    closediv.style["fontFamily"] = "monospace";
    closediv.style["padding"] = "0px 5px";
    closediv.style["cursor"] = "pointer";
    closediv.style["border"] = "1px solid #666666";
    closediv.innerHTML = "x";

    var me = this;
    GEvent.addDomListener(closediv,'click',function() {
      if ( me.shown ) me.hide();
    });

    wrapper.appendChild(closediv);

    var infopane = document.createElement("div"); 
    wrapper.appendChild(infopane);

    var me = this;
    GEvent.addListener(map,'click',function(overlay) {
      if ( overlay == null ) {
        me.hide();
      }
    });

    this.dom = wrapper;
    this.contents = infopane;
    this.map = map;
    map.getContainer().appendChild(wrapper);  
    return wrapper;
  },

  setMessage: function(contents) {
    this.contents.innerHTML = contents;
  },

  getContainer: function() {
    if ( typeof(this.dom) != "undefined" ) return this.dom;
    return null;
  },


  printable: function() {
    return this._printable;
  },

  selectable: function() {
    return this._selectable;
  },

  isHidden: function() {
    return ! this.shown;
  },

  show: function() {
    if (typeof(this.dom) == "undefined" ) return;
    this.shown = true;
    this.dom.style.display = "block";
    GEvent.trigger(this,'show');
  },

  hide: function() {
    if (typeof(this.dom) == "undefined" ) return;
    this.shown = false;
    this.dom.style.display = "none";
    GEvent.trigger(this.map,'extinfowindowclose');
    //this.dom.style.zIndex = "0";
  },

  getDefaultPosition: function() {
    return new GControlPosition(G_ANCHOR_BOTTOM_LEFT, 
                            new GSize(71,0));
  }

});

