(function () {
	var zIndex = 1000;
	if (typeof window.sb === 'undefined')
		window.sb = {};
	
	var lightbox, overlay = $('<div class="lightbox-overlay" style="position:absolute; background-color: rgb(0,0,0);"></div>').click(hide);

	function showContent () {
		lightbox
			.css({ zIndex: zIndex + 1, left: -99000 })
			.appendTo('body')
			.css({ 
				left: (overlay.width() - lightbox.outerWidth()) / 2,
				top: ($(window).height() - lightbox.outerHeight()) / 2 + $(window).scrollTop()
			})
			.fadeIn(150);
	}

	function hideOverlay () {
		overlay.fadeOut(150, function () { $(this).remove(); });
	}

	function hide () {
		lightbox.fadeOut(150, function () { $(this).remove(); hideOverlay(); });
		return false;
	}

	function startLightbox (markup) {
		lightbox = (typeof markup === 'string' ? $(markup) : markup);
		lightbox.delegate('.btn-close', 'click', hide);
		overlay
			.css({ 
				opacity: 0.65, 
				top: 0, 
				left: 0, 
				width: $(document).width(),
				height: $(document).height(),
				zIndex: zIndex })
			.hide()
			.appendTo('body')
			.fadeIn(200, showContent);
	}

	window.sb.lightbox = {
		show : startLightbox,
		hide : hide
	}
})();



