/*
 * @(#)jquery.xlt.lightBox-1.0.js		1.00 11/10/10
 *
 * Copyright (c) 2011 SG Büromedien GmbH
 * Märkischer Ring 120, 58097 Hagen, Deutschland
 * All rights reserved.
 * 
 * @author		Marcus Holtgräwe
 * @version		1.0 10 Oct 2011
 */

(function($) {	
	$.fn.lightBox = function(value) {
		if ((value === undefined) || (typeof value == 'object')) {
			if ($.fn.lightBox.defaults === undefined) {
				$.fn.lightBox.defaults = {
					buttonLabel : 'Weiter'
				};
			}
						
			var options = $.extend({}, $.fn.lightBox.defaults, value || {});
				
			var pane$ = this;
			pane$.detach().appendTo($('body'));
			
			var overlay$ = $('.lightbox-overlay:first');
			if (overlay$.length <= 0) {
				overlay$ = $('<div/>').addClass('lightbox-overlay');
				$('html').prepend(overlay$);
								
				overlay$.css({
				   'opacity' 			: '0.5',
				   'position' 			: 'fixed',
				   'display' 			: 'none',
				   'background-color' 	: '#60b1cf',
				   'left' 				: '0px',
				   'top' 				: '0px',
				   'width'				: '100%',
				   'height'				: '100%',
				   'z-index'			: '99999'
				});
			}
						
			$(overlay$).click(function() {
				closeLightbox();				
			});

			pane$.addClass('lightbox');
			
			$('.close', pane$).click(function() {
				closeLightbox();
			});
			
			$('button', pane$).text(options.buttonLabel);
			$('button', pane$).click(function() {
				closeLightbox(options.clickHandler);
			});
			
			function closeLightbox(callback) {
				pane$.fadeOut('fast');
				overlay$.fadeOut('fast', function() {
					overlay$.hide();
					if (callback) {
						callback.call();
					}
				});
			};
			
		} else if (typeof value == 'string') {
			if (value == 'show') {
				var overlay$ = $('.lightbox-overlay:first');
				var pane$ = $(this);
				overlay$.fadeIn(function() {
				   	pane$.css('top',
				   			($(window).height() - pane$.outerHeight()) / 2);
				   	pane$.css('left',
				   			($(window).width() - pane$.outerWidth()) / 2);
				   	pane$.show('clip');
				});
			}
		}
		
		return this;
	};
})(jQuery);
