/* center function */
jQuery.fn.center = function () { this.css("position","absolute"); this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop()); this.css("left", ( $(window).width() - this.width() ) / 2); return this; }

function doLightbox() {
	/* lightbox div HTML */
	var lightBoxHTML = '<div class="dimTheLights" id="dimTheLights"><div class="lightBox" id="lightBox"><div id="lightBoxIMG" class="lightBoxIMG"></div><div id="lightBoxCaption" class="lightBoxCaption"><!-- --></div><div id="btnClose"><a href="#" class="btnClose">x</a></div></div></div>';

	/* lightbox activate on click */
	$('.btnLightBox').click(function(){

		/* append lightbox to page */
		$('body').append(lightBoxHTML);

		/* set dimTheLights height to document height and fade in 'slow' */
		$('#dimTheLights').css('height', $(document).height()).fadeIn('slow');

		/* set width, height, img src and caption from <a> attributes */
		$('#lightBoxIMG').css('width', $(this).attr('width')); $('#lightBoxIMG').css('height', $(this).attr('height'));
		$('#lightBoxIMG').css('background-image', 'url("' + $(this).attr('rel') + '")');
		$('#lightBoxCaption').html($(this).find('img').attr('title'));

		/* center lightbox on screen */
		$('#lightBox').center();

		/* close functions on btnClose and dimTheLights click, preventing close on lightbox click */
		$('.btnClose').click(function(){
			$('#dimTheLights').fadeOut('slow', function(){ $(this).remove(); } );
			return false;
		});
		$('#dimTheLights').click(function(){
			$('#dimTheLights').fadeOut('slow', function(){ $(this).remove(); } );
			return false;
		});
		$('#lightBox').click(function(){ return false; });

		/* turn off right-click for lightbox */
		$('#lightBox').bind('contextmenu', function(){ return false; });

		/* keep lightbox centered */
		$(window).scroll(function(){ $('#lightBox').center(); });
		$(window).resize(function(){ $('#lightBox').center(); });	

		return false;
	});
}
