var modalBlock=false;
window.addEvent('domready', function(){
	$$('a.lightbox').each(function(el){
		el.onclick=function(){
			window.imageToLoad=el.getAttribute('href');
			goModal(loadImage);
			return false;
		}
	});
	if(window.location.href.test('failedlogin')){
		alert("The username or password you entered was invalid.");
	}
});

function goModal(callBack){
	modalBlock=new Element("DIV");
	modalBlock.setStyles({
		width:'100%',
		height:document.getScrollSize().y,
		position:'absolute',
		left:0,
		top:0,
		opacity:0,
		backgroundColor:'#000'
	});
	modalBlock.injectInside(document.body);
	modalBlock.fader=new Fx.Tween(modalBlock, {duration:200}).start('opacity', [0, .8]);
	if(callBack){
		callBack();
	}
}

function killModal(){
	if(modalBlock){
        modalBlock.fader.addEvent("onComplete", function(){
			modalBlock.destroy();
			modalBlock=false;
        });
		modalBlock.fader.start('opacity', [.7, 0]);
	}

}

function loadImage(){
	im=new Element('IMG');
	im.setStyle('opacity', 0);
	im.addEvent('load', function(){
		this.setStyles({
			display:'block',
			position:'absolute',
			left:'50%',
			top:window.getScrollTop()+(window.getHeight()/2)-(im.getHeight()/2),
			border:'solid 10px #FFFFFF',
			marginLeft:-(this.getWidth()/2)
		});
		new Fx.Tween(this).start('opacity', 1);
	});
	im.src=window.imageToLoad;
	im.injectInside(document.body);
	im.addEvent('click', function(){
		new Fx.Tween(this, {onComplete:function(){
				killModal();
				this.element.destroy();
		}}).start('opacity', 0);
	});
}