var Home2Popup = new Class({

  Extends: Mask,

  options: {
    hideOnClick: true
  },

  initialize: function(popup){
    this.popup = document.id(popup);
    this.parent(document.id(document.body));
    var scrollResize = this.handleWindowScrollOrResize.bind(this);
    window.addEvents({
      'scroll': scrollResize,
      'resize': scrollResize
    });
    this.close = this.popup.getElement('a.close');
    if (this.close) this.close.addEvent('click', this.handleCloseClick.bindWithEvent(this));
  },

  render: function(){
    this.parent();
    this.content = new Element('div').setStyle('display', 'none');
    this.popup.inject(this.content);
  },

  inject: function(target, where){
    this.parent(target, where);
    this.content.injectAfter(this.element);
  },

  show: function(){
    var h = this.hidden;
    this.parent();
    if (h){
      this.handleWindowScrollOrResize();
      this.content.setStyles({'z-index': this.element.getStyle('z-index'), 'display': 'block'});
    }
    return this;
  },

  hide: function(){
    if (!this.hidden){
      this.content.setStyle('display', 'none');
    }
    this.parent();
  },

  handleWindowScrollOrResize: function(){
    if (!this.hidden){
      var win = window.getScrollSize();
      var chromebugfix = Browser.Engine.webkit ? (win.x - 25 < document.html.clientWidth ? document.html.clientWidth : win.x) : win.x;
      this.resize(chromebugfix, win.y);
      this.content.position();
    }
  },

  handleCloseClick: function(e){
    e.stop();
    this.hide();
  }

});

