/**
 * Overlay
 */
var Overlay = Class.create({
  /**
   * Init VOverlay
   */
  initialize: function(overlayElem, overlayTintElem) {
  	this.overlayElem = overlayElem;
  	this.overlayTintElem = overlayTintElem;
			
	  // btn handlers
    this.overlayTintElem.observe('click', this.onCloseBtn.bind(this));	
  	
	  Event.observe(window, 'resize', this.repaint.bind(this));
    if (!Prototype.Browser.MobileSafari) {	
      Event.observe(window, 'scroll', this.repaint.bind(this));
    }
	  this.repaint();	      	
  },
  
  show: function() {
	  this.overlayTintElem.style.display = "block";
	  this.overlayTintElem.style.visibility = "visible";
	  
	  this.overlayElem.style.display = "block";
	  this.overlayElem.style.visibility = "visible";
  },

  hide: function() {
	  this.overlayTintElem.style.display = "none";
	  this.overlayTintElem.style.visibility = "hidden";
	  
	  this.overlayElem.style.display = "none";
	  this.overlayElem.style.visibility = "hidden";
  },
  
  repaint: function(evt) {
	  var offsets = document.viewport.getScrollOffsets();
	  var viewDim = document.viewport.getDimensions();
				  
    if (Prototype.Browser.MobileSafari) {	
  	  this.overlayTintElem.style.width = viewDim.width + "px";
	    this.overlayTintElem.style.height = viewDim.height + "px";
    }
    else {
  	  this.overlayTintElem.style.width = viewDim.width + offsets.left + "px";
  	  this.overlayTintElem.style.height = viewDim.height + offsets.top + "px";
    }	
  },
  
  onCloseBtn: function(evt) {
    this.hide();    
  }  

});

