// Lightbox effect
function positionLightboxImage() {
	var top = ($(window).height() - $('#lightbox').height()) / 2;
	var left = ($(window).width() - $('#lightbox').width()) / 2;
	$('#lightbox').css({
		'top': top + $(document).scrollTop(),
		'left': left
	}).fadeIn();
}

function removeLightbox() {
	$('#overlay, #lightbox').fadeOut('slow', function() {
		$(this).remove();
		$('body').css('overflow-y', 'auto'); // show scrollbars!
	});
}

// Infinite blink/fade
function effectFadeIn(classname) {
	$("." + classname).fadeOut(800).fadeIn(800, effectFadeOut(classname));
}

function effectFadeOut(classname) {
	$("." + classname).fadeIn(800).fadeOut(800, effectFadeIn(classname));
}

$(document).ready(function(){
	$('a.lightbox').click(function(e) {
		$('body').css('overflow-y', 'hidden'); // hide scrollbars!

		$('<div id="overlay"></div>')
		.css('top', $(document).scrollTop())
		.css('opacity', '0')
		.animate({'opacity': '0.5'}, 'slow')
		.appendTo('body');

		$('<div id="lightbox"></div>').hide().appendTo('body');

		$('<img />').attr('src', $(this).attr('href')).load(function() {
			positionLightboxImage();
		}).click(function() {
			removeLightbox();
		}).appendTo('#lightbox');

		return false;
	});
});
