$(document).ready( function() {
	/*$('a.lightbox').each(function() {
		$(this).click(function(){
			var imageLink = $(this).attr('href');
			loadInfo(imageLink);
			return false;						
		});
	});					*/
	$(window).resize(function () { positionLightBox();});
	$(window).scroll(function () { positionLightBox();});
});

function closeLightbox()
{
	$('#jquery-overlay').remove();
	$('#details-content').remove();
	$('#dlookman-promo').show();
	return false;
}

var lbWidth = 500;
var lbHeight = 500;
function loadInfo(imageLink, imageDesc)
{
	addOverlay();
	$('#jquery-overlay').after('<div id="details-content" style="z-index: 4000;background-color:white;"><table border="0" width="100%" style="height: '+lbHeight+'px"><tr><td align="left"><img alt="dLook" src="/staging/images/logo.gif"/></td><td align="right"><a class="closeLink" href="#" onclick="return closeLightbox();">close</a></td></tr><tr"><td colspan="2" align="center"><img src="'+imageLink+'" alt="Image" /></td></tr><tr><td><p style="text-align:left">'+imageDesc+'</p></td></tr><tr><td colspan="2" align="right"><a class="closeLink" href="#" onclick="return closeLightbox();">close</a></td></tr></table></div>');																																																													
																																																																																																																																																													
	$('#details-content').css('opacity', '1');
	$('#details-content').css('position', 'absolute');
	$('#details-content').css('padding', '10px');
	$('#details-content').css('z-index', '3000');
	$('#details-content').css('border', '2px solid #BC127D');
	$('#details-content').css('background-color', 'white');
	$('#details-content').css('width', lbWidth+'px');
	$('#details-content').css('height', lbHeight+'px');
	$('.closeLink').css('color', '#BC127D');
	positionLightBox();
	return false;
}

function addOverlay()
{
	$('body').append('<div id="jquery-overlay" onclick="closeLightbox();">&nbsp;</div>');
	$('#dlookman-promo').hide();
	$('#jquery-overlay').css('height', $(document).outerHeight());
	$('#jquery-overlay').css('opacity', 0);
	$('#jquery-overlay').fadeTo('normal', 0.8);
	
}

function positionLightBox()
{
	// Check to see if the display height of the screen is smaller than the default lightbox size
	// note: Ignoring width for now, it degrades a little better than the height does.
	if ($(window).innerHeight() < lbHeight) {
		// screen is smaller, adjust the lightbox height
		var topOffset = ($(window).scrollTop());
		$('#details-content').css('overflow', 'scroll')
		var tmpHeight = Math.min(lbHeight, $(window).innerHeight());
		$('#details-content').css('height', tmpHeight+'px');
	} else {
		// screen is bigger, center the lightbox on the screen
		var topOffset = ($(window).scrollTop()) + (($(window).innerHeight() - lbHeight)/2);
	}
	// Set the absolute positions for the lightbox
	$('#details-content').css('top', topOffset+'px');
	var leftOffset = (($('#jquery-overlay').outerWidth() - lbWidth)/2);
	$('#details-content').css('left', leftOffset+'px');
}

