var Lightbox = new Class({
	Implements: [Options, Events],
	
	overlay: null,
	content: null,
		close: null,
		body: null,
	showing: false,
	
	options: {},
	
	initialize: function (options) {
		this.setOptions(options);
	},
	
	show: function () {
		if(this.showing) return;
		this.showing = true;
		
		var calls = {
			overlay: function () {
				this.overlay = new Element('div', {
					styles: {
						opacity: 0,
						position: 'absolute', left: 0, top: 0,
						width: window.getScrollSize().x, height: window.getScrollSize().y
					},
					morph: {
						duration: 'short',
						onComplete: calls.content.bind(this)
					}
				}).inject($(document.body)).addClass('lightbox-overlay').morph({opacity: 0.6});
			},
			
			content: function () {
				this.content = new Element('div', {
					styles: {
						opacity: 0,
						position: 'absolute', top: (Window.getScrollTop() + 150) + "px"
					},
					morph: {
						duration: 'short',
						onComplete: calls.done.bind(this)
					}
				}).inject($(document.body)).addClass('lightbox-content').morph({opacity: 1});
			},
			
			done: function () {
				this.close = new Element('div', {
					events: {
						click: this.hide.bind(this)
					},
					text: 'X'
				}).inject(this.content).addClass('lightbox-close');
				this.body = new Element('div', {
				}).inject(this.content).addClass('lightbox-body');
				
				this.fireEvent('show');
			}
		};
		
		calls.overlay.run([], this);
		return this;
	},
	
	hide: function () {
		var calls = {
			content: function () {
				this.content.empty();
				this.content.set({
					morph: {
						duration: 'short',
						onComplete: calls.overlay.bind(this)
					}
				}).morph({opacity: 0});
			},
			
			overlay: function () {
				this.overlay.set({
					morph: {
						duration: 'short',
						onComplete: calls.done.bind(this)
					}
				}).morph({opacity: 0});
			},
			
			done: function () {
				this.overlay.dispose();
				this.content.dispose();
				
				this.overlay = null;
				this.content = null;
				this.showing = false;
				
				this.fireEvent('close');
			}
		};
		
		calls.content.run([], this);
		return this;
	}
});
