var Lightbox = Class.create({
	initialize: function (image_name, options) {
		this.options = Object.extend({
			width: 672,
			height: 552,
			close_image: '../_images/_lightbox_close.gif',
			css_prefix: 'Vx_lightbox_',
			duration: 0.6,
			opacity: 0.3
		}, options || {});
		
		this.image = new Element('img', {
			src: image_name,
			alt: '',
			width: this.options.width,
			height: this.options.height,
			className: this.options.css_prefix + 'image'
		});
		
		this.lightbox = new Element('div', { className: this.options.css_prefix + 'container' });
		this.blackout = new Element('div', { className: this.options.css_prefix + 'overlay' });
		
		this.close_icon = new Element('a', {
			href: '#close',
			rel: 'nofollow',
			className: this.options.css_prefix + 'close'
		});
		
		this.shim = new Element('iframe', {
			href: 'javascript:false;',
			className: this.options.css_prefix + 'shim',
			border: 0,
			frameborder: 0,
			scrolling: 'no'
		});
		
		$(this.blackout, this.close_icon).invoke('observe', 'click', function (event) {
			event.stop();
			this.close();
		}.bindAsEventListener(this));
	},
	
	close: function () {
		try {
			Effect.Fade(this.lightbox, { duration: this.options.duration, afterFinish: function () { try { $(this.lightbox, this.shim).invoke('remove'); } catch (err) {} }.bind(this) });
		} catch (first_fade_error) {}
		
		try {
			Effect.Fade(this.blackout, { duration: this.options.duration, afterFinish: function () { try { this.blackout.remove(); } catch (err) {} }.bind(this) });
		} catch (second_fade_error) {}
	},
	
	
	show: function () {
		this.blackout.hide();
		this.lightbox.hide().insert(this.image).insert(this.close_icon);
		
		$(this.blackout, this.shim, this.lightbox).each(function (element) {
			$(document.body).insert({ top: element });
		});
		
		Effect.Appear(this.blackout, { to: this.options.opacity, duration: this.options.duration });
		Effect.Appear(this.lightbox, { delay: this.options.duration / 2, to: 1, duration: this.options.duration });
	}
});