// JavaScript Document

function initLightBox(opt)
{
	$$('body').each(function(e){
		e.insert(new Element('div',{'class':'blackout', 'id':'lb_blackout', 'style':'display: none;'}));
		e.insert(new Element('div',{'class':'lightBoxContent', 'id':'lb_content', 'style':'display: none;'}));
		e.insert(new Element('div',{'class':'lightBoxCloseButton', 'id':'lb_closeButton', 'style':'display: none;'}));
		$('lb_closeButton').observe('click', hideLightBox);
		if (opt.onClose)
		{
			$('lb_content').hideCallbackFX = opt.onClose;
		}
		e.style.height = '100%';
	});
}

function showLightBox()
{
	$('lb_content').style.marginTop = (-($('lb_content').getHeight()/2))+'px';
	$('lb_content').style.marginLeft = (-($('lb_content').getWidth()/2))+'px';
	$('lb_closeButton').style.marginTop = (-(($('lb_content').getHeight()+ $('lb_closeButton').getWidth())/2))+'px';
	$('lb_closeButton').style.marginLeft = (-(($('lb_content').getWidth() + $('lb_closeButton').getWidth())/2))+'px';
	$('lb_blackout').appear({
		duration: 0.4,
		to: 0.7,
		afterFinish: function(){
			$('lb_content').appear({
				duration: 0.2,
				to: 1,
				afterFinish: function(){
					$('lb_closeButton').show();
					$('lb_blackout').hideFx = hideLightBox.bindAsEventListener();
					$('lb_blackout').observe('click', $('lb_blackout').hideFx);
				}
			});
		}
	});
}

function hideLightBox()
{
	$('lb_closeButton').hide();
	$('lb_blackout').stopObserving('click', $('lb_blackout').hideFx);
	$('lb_content').fade({
		duration: 0.2,
		to: 0,
		afterFinish: function(){
			$('lb_blackout').fade({
				duration: 0.4,
				to: 0,
				afterFinish: function(){
					if ($('lb_content').hideCallbackFX) { $('lb_content').hideCallbackFX(); }
				}
			});
		}
	});
}
