/*
 * Created 14 Mar 2010
 *
 */

function beamOverlay(name){
  if (! name){name ='overlay' + Math.floor(Math.random()*100000000)};

  //Variables
  this.name = name;

  //Functions
  this.show = overlayShow;
  this.hide = overlayHide;
  this.html = overlayHtml;
  this.size = overlaySize;
  this.position = overlayPosition;

  //Object
  //$('body').append('<div id="' + name + '"><div class="ui-overlay"><div class="ui-widget-overlay" ></div><div style="position: absolute; width: 50%; height: 50%; left: 0; top: 0;" class="ui-widget-shadow ui-corner-all beamPopupShadow"></div></div><div class="ui-widget ui-widget-content ui-corner-all beamPopup" style="position: absolute; padding: 10px;"><p>Please wait while data loads...</p></div></div>');
  $('body').prepend('<div id="overlay-' + name + '" class="ui-overlay"><div class="ui-widget-overlay"  style="width: 1263px; height: 1024px; z-index: 1001;"></div><div style="z-index: 1002; width: 302px; height: 152px; position: absolute; left: 50px; top: 30px;" class="ui-widget-shadow ui-corner-all beamPopupShadow"></div></div><div class="ui-widget ui-widget-content ui-corner-all beamPopup" style="position: absolute; width: 280px; height: 130px; left: 50px; top: 30px; padding: 10px; z-index: 1003;"><p>Please wait while data loads...</p></div>');
  this.overlay = $('div#overlay-' + name);
  this.overlay.css('display','none');
  this.popup = this.overlay.next('.beamPopup');
  this.popup.css('display','none');
  this.shadow = this.overlay.find('.beamPopupShadow');
  this.overlay.css('position', 'absolute');

  //Set default size and position
  this.size($(window).width()*0.8, $(window).height()*0.8);
  this.position($(window).height()*0.1, $(window).width()*0.1);
}

function overlayShow(){
  this.overlay.css('display','block');
  this.popup.css('display','block');
}

function overlayHide(speed){
  if (speed){
      this.overlay.delay(speed).css('display','none');
      this.popup.delay(speed).fadeOut('slow');
  }
  else {
      this.overlay.css('display','none');
      this.popup.fadeOut('slow');
  }
}

function overlayHtml(data){
  this.popup.html(data);
}

function overlaySize(width, height){
  this.popup.width(width);
  this.popup.height(height);
  this.shadow.width(width);
  this.shadow.height(height);
}

function overlayPosition(top, left){
  this.popup.offset({top: top, left: left});
  this.shadow.offset({top: top-20, left: left-20});
}
