/*  
 *  Input Custom 1.0
 *  Date : 06/04/2010  
 *
 */ 
 
(function($){
	$.fn.lightBox = function(parameters)
	{
		// attributes
		var element 		= $(this);
		var iniDefault		= {
        	event				: 'click',
            target			: 'a',
			background		: '#000000',
			border			: 'solid 3px #333',
			opacity			: '0.8',
			width				: '400',
			height			: '320',
			btCloseStyle	: {}
		}
		var vDefault 		= $.extend({},iniDefault,parameters);
		
		//divide o tamanho do lightBox por 2 (vertical)
		var mLeft		= vDefault.width.replace('px','');
		mLeft				= eval(mLeft) / 2;
		
		//divide o tamanho do lightBox por 2 (horizontal)
		var mTop		= vDefault.height.replace('px','');
		mTop				= eval(mTop) / 2;
		
		$("body").prepend('<div class="lightBox"><span class="tl">&nbsp;</span><span class="tr">&nbsp;</span><span class="bl">&nbsp;</span><span class="br">&nbsp;</span><a href="#" class="lightBoxClose">X</a><div class="lightBoxContent"></div></div>');
        $("body").prepend('<div class="lightBoxBackground"></div>');
		    
        var elementContent = $(vDefault.target).html();
        $(vDefault.target).hide();
        $(".lightBox .lightBoxContent").html(elementContent);
			
		var hideLightBox = function(){
			$(".lightBoxBackground").animate({
				opacity		: 0
			},1000);
	            
	        $(".lightBox").animate({
	            height		: 0,
	            opacity		: 0
	        },500,function(){$(".lightBoxBackground").hide(); $(".lightBox").hide()});
		};
				
        $(".lightBoxBackground").css({
        	width				: "100%",
            height			: "99999px",
            position			: "fixed",
            top				: "0",
            left				: "0",
            zIndex			: "1000",
            background		: vDefault.background,
            opacity			: 0
        });
            
		$(".lightBoxBackground").hide();
		$(".lightBox").hide()
            
        $(".lightBox").css({
			width				: vDefault.width,
            height			: 0,
            position			: "fixed",
            top				: "50%",
			left				: '50%',
			marginTop		: -mTop,
			marginLeft		: -mLeft,
            zIndex			: "1001",
            border			: vDefault.border,
            opacity			: 0,
			padding			: '10px'
        });
		
		//Botão fechar modal
		$(".lightBox .lightBoxClose").click(function(){
			hideLightBox();
			return false;
		});
		$(".lightBox .lightBoxClose").css(vDefault.btCloseStyle);
		
		$(element).bind(vDefault.event, function() {
			var elementContent = $(vDefault.target).html();
			$(".lightBox .lightBoxContent").html(elementContent);
        
            $(".lightBoxBackground").animate({
                opacity		: vDefault.opacity
            },500);
            
            $(".lightBox").animate({
               	//width		: vDefault.width,
				height		: vDefault.height,
				opacity		: 1
            },500);
		
			$(".lightBoxBackground").show();
			
			
			return false;
		});	
	}
})(jQuery);
