var PopUp = function()
{
   this.pp = new Array();
   var bind = this;

   this.onKeyUp = function(e)
   {
      var e = e || window.event;
      if (e.keyCode == 27)
      {
         var id = bind.pp.pop();
         if (id == undefined) return;
         bind.hide(id);
         controls.stopEvent(e);
         if (!e.preventDefault) e.keyCode = 0;
      }
   };

   controls.addEvent(document, 'keyup', this.onKeyUp);

   this.initialize = function(id)
   {
      var fade = controls.$('fade_' + id);
      if (!fade)
      {
         fade = document.createElement('div');
         fade.id = 'fade_' + id;
         fade.className = 'shadow';
         fade.style.display = 'none';
         fade.style.zIndex = controls.getStyle(id, 'zIndex') - 1;
         document.body.appendChild(fade);
      }
   };

   this.show = function(id, opacity, centre)
   {
      if (centre == undefined) centre = 1;
      if (opacity == undefined) opacity = 0.5;
      if (typeof(hideBadElements) == 'function') hideBadElements();
      controls.fade('fade_' + id, true, opacity);
      controls.display(id, '');
      if (centre > 0) controls.centre(id);
      this.pp.push(id);
   };

   this.hide = function(id)
   {
      if (typeof(showBadElements) == 'function') showBadElements();
      controls.fade('fade_' + id, false);
      controls.display(id, 'none');
   };
};

var popup = new PopUp();
