
var InnerPopupsManager = new Class({
  opened_list: [],		
  available_list: [],
  el_container: null,
  el_alphascreen: null,
  flash_content_height: null,
  
  initialize: function()
  {
    this.el_container = $$('.popups_container')[0];
    this.el_alphascreen = this.el_container.getElement('.alphascreen');
    this.flash_content_height = $('flash_content').height ? $('flash_content').height : $('flash_content').style.height ;

    _this = this;
    $each(this.el_container.getElements('.popup'), function(el) {
      _this.available_list.push(el);

      el.getElement('.popup_bar a.close').addEvent('click', function(e) {
      _this.closeAll();
        e.preventDefault();
      });
    });
  },
  
  open: function(popup, arguments)
  {
    if (this._flashIsAlwaysOnTop())
      $('flash_content').style.height = '1px';
      //$('flash_content').style.visibility = 'hidden';

    popup = $(popup);
    this.el_container.setStyle('display', 'block');
      console.log(this.el_container);
    this.el_alphascreen.setStyle('opacity', '0.8');
    this.el_alphascreen.setStyle('height', window.getSize().y + 'px');

    popup.setStyle('display', 'block');
    this.opened_list.push(popup);
  },
  
  closeAll: function()
  {
    this.opened_list.each(function(el) {
      el.setStyle('display', 'none');
    });
    this.el_container.setStyle('display', 'none');

    if (this._flashIsAlwaysOnTop())
      $('flash_content').style.height = this.flash_content_height;
      //$('flash_content').style.visibility = 'visible';
  },
  
  _flashIsAlwaysOnTop: function()
  {
    var wmode = $$('#flash_content param[name=wmode]')[0].value;
    return (wmode == 'direct' || wmode == 'window');
  }
});

InnerPopupsManager.getInstance = function() {
  if (!this.instance)
  {
    this.instance = new InnerPopupsManager();
  }
  return this.instance;
};
