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.closeButton = new Element('p', { 'class' : 'close' }).inject(this.overlayWindow);
		this.closeLinkTop = new Element('a', { 'text' : 'Close this window', 'style' : 'cursor:pointer;' }).inject(this.closeButton);
		this.contents = new Element('div', { 'id' : 'contents' }).inject(this.overlayWindow);
		this.closeLinkBottom = this.closeLinkTop.clone().inject(this.closeButton.clone().empty().inject(this.overlayWindow));
		
		var closeAction = function() { this.hide(); return false; }
		var boundHide = closeAction.bind(this);
		this.closeLinkTop.addEvent('mouseup', boundHide);
		this.closeLinkBottom.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);
		}	
		
		winSize = window.getScrollSize();
		this.overlayWindow.setStyles({ 'left' :  ((winSize.x ) / 15), 'top' : window.getScrollTop() + 20 });	

		this.overlayWindow.setStyle("left", window.getScrollSize().x * 0.025 );	
		
		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); 
	}
});