var Overlay = new Class({

	initialize: function(){
	    this.overlayMask = new Element('div', { 'id' : 'overlay-mask' }).setStyles({'background-color' : '#000', 
	    																			'width' : '100%', 
	    																			'height' : '100%', 
	    																			'position' : 'fixed', 
	    																			'top' : '0', 
	    																			'left' : '0', 
	    																			'z-index' : '100'
	    																			}).fade('hide');
		compatibleOverlay = Browser.Engine.trident4 || (this.overlayMask.currentStyle && (this.overlayMask.currentStyle.position != "fixed"));																			
		if (compatibleOverlay) this.overlayMask.setStyles({'width': window.getScrollSize().x, 'height': window.getScrollSize().y, 'position': 'absolute'});
		
		this.overlayWindow = new Element('div', { 'id' : 'overlay' }).fade('hide');
		this.contents = new Element('div', { 'id' : 'contents' }).inject(this.overlayWindow);
		this.closeButton = new Element('p', { 'id' : 'close' }).inject(this.overlayWindow);
		this.closeLink = new Element('a', { 'text' : 'Close this window', 'href' : '#' }).inject(this.closeButton);

		var closeAction = function() { this.hide(); return false; }
		var boundHide = closeAction.bind(this);
		this.closeLink.addEvent('mouseup', boundHide);
			
		this.overlayMask.set('tween', {duration: '400'});
	    this.overlayWindow.set('tween', {duration: '400'});
		
		$(document.body).adopt(this.overlayWindow, this.overlayMask);		
	},	

	show: function(content){
		if (content) {
		    this.contents.empty()
		    content.clone().inject(this.contents);
		}	
		
		var scroll = window.getScroll(), size = window.getSize();
		this.overlayWindow.setStyle("left", ( (size.x / 2) - (this.contents.getSize().x / 2) ));	
		
		this.fadeInOverlayMask.bind(this).delay('0');
	    this.fadeInOverlayWindow.bind(this).delay('200');
	},
		
	hide: function(){
	    this.overlayMask.fade('out');
	    this.overlayWindow.fade('out');
	},
	
	fadeInOverlayMask: function(){
		this.overlayMask.fade(0, 0.8);
	},
	
	fadeInOverlayWindow: function(){		
		this.overlayWindow.fade(0,1); 
	}
});