/**
 *		simpel dialoge
 * 	
 * 		@copyright 2010 iSource B.V.
 *		@version 1.2 
 * 
 */


(function($){
	$.fn.lightbox = function(options) {  
       	var defaults = {  
			dialogeHeight: '150',
			dialogeWidth: '300',
			dialogeBackground : 'red',
			zIndex : 999999,
			exitClass: 'exit',
			dialogeHtml: ''
		};  
     
       	var options = $.extend(defaults, options);
   
        return this.each(function() {  

        	if($("#dialoge").length == 0 ){
        		dialoge = $("<div id=\"dialoge\" >").html(options.dialogeHtml);
            	$("body").prepend(dialoge);
            	
        		dialoge.css({
	        		'width' 	:	options.dialogeWidth+'px',
	        		'height'	:	options.dialogeHeight+'px',
	        		'position'	: 	'absolute',
	        		'background':  	options.dialogeBackground,
	        		
	        		'left'		:   '50%',
	        		'margin-left' : '-'+(options.dialogeWidth/2)+'px',
	        		
	        		'top'		:  	'50%',			
	        		'margin-top':  	'-'+(options.dialogeHeight/2)+'px',
	        		'z-index' :		options.zIndex,
	        		'display'	:   'none'
	           	});
        	}
        	
        	if($("#dialogeBackground").length == 0 ){
	        	dialogeBackground = $("<div id=\"dialogeBackground\" >").html("");
	        	$("body").prepend(dialogeBackground);
	        	
	        	dialogeBackground.css({
	        		'width' 	:	'100%',
	        		'height'	:	'100%',
	        		'position'	: 	'absolute',
	        		'background':  	'#000',
	        		'z-index' 	:	(options.zIndex-1),
	        		'opacity'   :   0.5,
	        		'display'	:   'none'
	        	});
        	}
        	
        	$('body').css('overflow', 'hidden');
        	
        	dialogeBackground.fadeIn("slow");
     		dialoge.fadeIn("slow");
        	
        	dialogeBackground.click(function(){
        		exit();
        	});
        	
        	$('.'+options.exitClass).click(function(){
        		exit();
        	});
        	
        	
      	});

        
       function exit(){
    	   dialogeBackground.fadeOut("slow");
   		   dialoge.fadeOut("slow");
   		$('body').css('overflow', 'auto');
       }
	};
})(jQuery);
