var Lightbox = {
	washout: null,
	washout_watcher: null,
	onhide: null,

	show: function (content_element, onhide) {
		var body = document.body;
		content_element = $(content_element);

		var washout = new Element('div', {'id': 'washout'});
		washout.setStyle({
			position: 'fixed',
			opacity: 0.0
		});
		if (/MSIE [3-6]/.match(navigator.appVersion)) {
			washout.setStyle({position: 'absolute'});
			washout.setStyle({top: document.documentElement.scrollTop + 'px'});
		}
		body.appendChild(washout);
		Lightbox.update_washout();
		Lightbox.washout_watcher = setInterval(Lightbox.update_washout, 20);

		new FadeIn('washout', {to: 0.6, duration: 0.5});

		content_element.setStyle({display: 'block', visibility: 'hidden'});
		body.appendChild(content_element);

		content_element.style.position = 'absolute';
		Lightbox.recenter(content_element);
		content_element.style.zIndex = '10000';
		content_element.setStyle({display: 'none', visibility: 'visible'});
		new FadeIn(content_element, {delay: 0.4, duration: 1});

		Lightbox.washout = washout;		
		Lightbox.onhide = onhide;

		if (onhide)
			Event.observe(this.washout, 'click', Lightbox.hide);
	},

	recenter: function (content_element) {
		content_element.style.left = (document.documentElement.scrollLeft + document.body.scrollLeft + (document.documentElement.clientWidth - content_element.offsetWidth) / 2) + 'px';
		var top = (document.documentElement.scrollTop + document.body.scrollTop + (document.documentElement.clientHeight - content_element.offsetHeight) / 2);
		content_element.style.top = Math.max(top, 25) + 'px';
	},

	update_washout: function () {
		$('washout').setStyle({
			width: document.documentElement.clientWidth + 'px',
			height: document.documentElement.clientHeight + 'px'
		});
	},

	hide: function () {
		Lightbox.finalize();
		if (Lightbox.onhide) {
			Lightbox.onhide();
		}
	},

	finalize: function () {
		clearInterval(Lightbox.washout_watcher);
		Lightbox.washout.remove();
	}
};
