$(document).ready(function()
{
	geba.initLightbox();
});

var geba = {};

// Lightbox
geba.initLightbox = function()
{
	$('[rel*=lightbox]').bind('click', function(e)
	{
		// Overlay
		var imageLoc = this.href;
		var overlay = $('<div>')
			.addClass('lightbox-overlay')
			.css({
				height: $(document).height(),
				width: $(window).width()
			})
			.appendTo('body')
			.css({opacity: 0})
			.animate({opacity: .8}, 200);

		// Image container
		var container = $('<div>')
			.addClass('lightbox-container')
			.appendTo('body')
			.bind('click', function(e)
			{
				$(container).fadeOut(200, function(){ $(this).remove(); });
				  $(overlay).fadeOut(200, function(){ $(this).remove(); });
			});

		// Vertical offset for funny browsers that dont support position: fixed
		var vOffset = 0;
		if ($.browser.msie && $.browser.version < 7)
		{
			vOffset = document.documentElement.scrollTop;
		}

		// Load image
		var image = $('<img src="' + this.href + '">')
			.load(function()
			{
				// Hide spinner
				container.css({
					background: 'none'
				});

				// Append image and fade in
				$(this)
					.appendTo('.lightbox-container')
					.attr('title', 'Klik om terug te gaan naar de website')
					.css({
						marginTop:	vOffset + this.offsetHeight / -2,
						marginLeft:	this.offsetWidth / -2,
						opacity:	0
					})
					.animate({opacity: 1}, 200);
			});
		return false;
	});
}
