var LightBox = Class.create({
	initialize: function(options) {
		$H({triggerId: 'lightbox_trigger',
		    contentId: 'lightbox',
		    overlayId: 'overlay',
		    closeButtonId: 'lightbox_close',
		    fadeInDuration: .2,
		    fadeOutDuration: .2,
		    distanceFromViewportTop: 50
		}).merge(options).each(function(option) {
			this[option.key] = option.value;
		}, this);			
			
		this.triggers = $$(this.triggerSelector);
		this.content = $(this.contentId);
		this.overlay = $(this.overlayId);	
		this.closeButton = $(this.closeButtonId);
		this.overlay.hide();
		this.content.hide();
		this.registerEventHandlers();
	},
	registerEventHandlers: function() {
        this.triggers.invoke("observe", "click", this.open.bindAsEventListener(this));
        [this.overlay, this.closeButton].invoke('observe', 'click', this.close.bindAsEventListener(this));        
	},
	open: function(e) {
		if (e) e.stop();
		
		this.content.setStyle({'top': (document.body.cumulativeScrollOffset()[1] + this.distanceFromViewportTop) + 'px'});
		this.overlay.appear({ duration: this.fadeInDuration, from: 0, to: .5 });
		this.content.appear({ duration: this.fadeInDuration, afterFinish: function() {
			if (typeof embedMovie != 'undefined') {
				embedMovie();
			}		
		} });
	},
	close: function(e) {
		if (e) e.stop();
		this.overlay.fade({ duration: this.fadeOutDuration, from: .5, to: 0 });
		this.content.fade({ duration: this.fadeOutDuration, afterFinish: function() {
			if (typeof unembedMovie != 'undefined') {
				unembedMovie();
			}		
		} });
	}
});  				    
			    
// Sample instantiation:
//
//				new LightBox({
//					'triggerSelector': '.watch_video',
//					'contentId': 'lightbox'
//				});
