var Overlay = new Class({

	Implements: [Options, Events],

	initialize: function(options){
		this.setOptions(options);
		this.crapBrowser = (Browser.Engine.trident && Browser.Engine.version <= '4');
	},
	
	show: function(variable){
		this.overlay().inject(document.body, 'bottom');
		(this.options.transition) ? $(this.options.id).getElement('div').fade(this.options.opacity) : $(this.options.id).getElement('div').set('opacity', this.options.opacity);
		(this.options.transition) ? (function(){ this.fireEvent('onShow'); }).delay(500, this): this.fireEvent('onShow', variable);
	},
	
	hide: function(variable){		
		if(this.options.transition){					
			$(this.options.id).getElement('div').fade('out');
			(function(){ $(this.options.id).dispose(); }).delay(500, this);
		}else{
			$(this.options.id).dispose();
		}
		this.fireEvent('onHide', variable);
		this.removeEvents();
	},

	overlay:  function(){
		var size = window.getScrollSize(),
			overlay = new Element('div',{'id': this.options.id});
			
		if(this.crapBrowser){
			new IFrame({
				'src': 'about:blank',
				'frameborder': 0,
				'scrolling': 'no',
			    'styles': {
			    	'filter': 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)',
					'width': size.x,
					'height': size.y,
					'z-index': 10,
					'position': 'absolute',
					'top': 0,
					'left': 0
			    }			    
			}).inject(overlay);
		}
		new Element('div', {		
			    'styles': {
					'width': size.x,
					'height': size.y,
					'z-index': 11,
					'position': 'absolute',
					'top': 0,
					'left': 0,
					'opacity': 0.1,
					'background-color':this.options.color
			    },
			    'events': {
			        'click': function(){
			        	if(this.options.hideOnOverlayClick) this.hide();
			        	this.fireEvent('onOverlayClick');
			        }.bind(this)
			    }
			}).inject(overlay);
		return overlay;
	},
	
	options: {
        opacity: 0.7,
        color: '#333333',
        id: 'overlay',
        hideOnOverlayClick: false,
        transition: true
        //onOverlayClick: $empty
        //onShow: $empty
        //onHide: $empty
    }
});