/*****************************************
*
* simple implementation of overlay popup
*
* (c)2010 colcode
*
 ****************************************/

var Popup = new function()
{
   var is_ok = false;
   var _me   = this;
   var elm   = false;
   var pop   = false;
   var dim   = false;
   
   var pw    = 656;   // default popup width
   var ph    = 300;   // default popup height
   var el    = false; // element id to auto load
   
   this._real = function(id, ol)
   {
      if(typeof id == 'undefined') return;
      if(typeof ol == 'undefined') ol = true;
      
      if(ol && !dim && !pop) _me.create();
            
      if(!pop) return;
      
      pop.style.display = 'block';
      
      if(!ol) return;
      
      dim.style.display = 'block';
   }
   
   this.create = function()
   {
      // create a dim Layer
      dim = document.createElement('div');
      dim.className = 'popup_dim';
      
      pop = document.createElement('div');
      pop.className = elm.className;
      
      var t = elm.innerHTML;
      elm.innerHTML = '';
      pop.innerHTML = t;
      
      document.body.appendChild(dim);
      document.body.appendChild(pop);
      //alert('hey');
   }
   
   this.hide = function()
   {
      if(dim) dim.style.display = 'none';
      if(pop) pop.style.display = 'none';
      return false;
   }
   
   this.show = function(id, ol)
   {
      if(typeof id == 'undefined') return;
      if(typeof ol == 'undefined') ol = true;
      
      elm = document.getElementById(id);
      
      if(is_ok)
         _me._real(id, ol);
      else
         el = { id : id, ol : ol }; // delayd execution
   }
   
   this.ready = function()
   {
      is_ok = true;
      if(el) _me._real(el.id, el.ol);
   }
   
   if(window.addEventListener)
      window.addEventListener('load', this.ready, false);
   else
      window.attachEvent('onload', this.ready);
};

/* eof */

