Blackout = Class.create({

  initialize: function(){
    this.overlay = new Element("div",{id:"blackout", style: "display:none;"})
    $$('body')[0].appendChild(this.overlay)
    this.overlay.observe("click", this.close.bind(this))
    this.afterClose = Prototype.emptyFunction;
    this.beforeClose = Prototype.emptyFunction;
    this.afterOpen = Prototype.emptyFunction;
  },

  activate:function(){
     var arrayPageSize = this.getPageSize();
     this.overlay.setStyle({ width: arrayPageSize[0] + 'px', height: arrayPageSize[1] + 'px' })
     this.overlay.appear({to: 0.9, queue: "front", duration:0.2});
     this.afterOpen();
  },

  close:function(options){
    this.beforeClose();
    options = options || {}
    options.duration = 0.2;
    this.overlay.fade(options);
    this.afterClose();
  },

  //  getPageSize()
  getPageSize: function() {

  var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;

	if (self.innerHeight) {	// all except Explorer
  	windowWidth = document.documentElement.clientWidth ? document.documentElement.clientWidth : self.innerWidth
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	pageHeight = yScroll < windowHeight ? windowHeight : yScroll

	// for small pages with total width less then width of the viewport
	pageWidth = xScroll < windowWidth ? xScroll : windowWidth

	return [pageWidth,pageHeight];
	}

})

