(function($){  
	$.fn.LightContent = function(options) {  
		
		var lcURL;
		var lcTitle;
		var lcOverlay;
		var lcFade;
		var lcAnimate;
		var lcOverlayOpacity;
		var lcOverlayBackground;
		var lcCloseText;
		
		if( options )
		{
			// a title for the window
			options.title ? lcTitle = options.title : lcTitle = false;
			// the url for the ajax request
			options.url ? lcURL = options.url : lcURL = false;
			// overlay on / off   default: on
			options.overlay ? lcOverlay = options.overlay : lcOverlay = true;
			// using fade animations  default: yes
			options.fade ? lcFade = options.fade : lcFade = true;
			// using animations for resize  default: yes
			options.animate ? lcAnimate = options.animate : lcAnimate = true;
			// the overlay opacity   default: 0.6
			options.opacity ? lcOverlayOpacity = options.opacity : lcOverlayOpacity = 0.6;
			// the backgroundcolor of the overlay  default: #000000 ( black )
			options.backgroundColor ? lcOverlayBackground = options.backgroundColor : lcOverlayBackground = "#000000";
			// the closing text 
			options.closeText ? lcCloseText = options.closeText : lcCloseText = "Schlie&szlig;en";
		}
		
		function CloseLightContent() {
			if( lcFade ) 
			{
				$("#lp-lc-content").fadeOut(300, function(){ $("#lp-lc-content").remove(); });
				$("#lp-lc-overlay").fadeOut(800, function(){ $("#lp-lc-overlay").remove(); });
			} else {
				$("#lp-lc-overlay").remove();
				$("#lp-lc-content").remove();
			}
		}
		
		return this.each(function() {   
			// edit the link 
			$(this).attr("href", "javascript: void(0);");
			// set a event listener on click event
			$(this).click(function() {
				
				if(!$("#lp-lc-overlay").attr("id"))
				{
					// adding the code to the html body
					
					// if we use an overlay
					if( lcOverlay )
					{
						// styles of the overlay
						var overlayStyle = "position: fixed; top: 0px; left: 0px; width: 100%; height: " + $(document).height() + "px; z-index: 99; background-color: #000000;";
						
						if( $.browser.msie ) 
							overlayStyle += "filter: alpha(opacity:0);";
						else
							overlayStyle += "opacity: 0;";
						
						// add code
						$("body").append("<div id=\"lp-lc-overlay\" style=\"" + overlayStyle + "\"></div>");
							// event listener to overlay
							$("#lp-lc-overlay").dblclick(CloseLightContent);
							
							if( lcFade )
							{
								// overlay animation
								$("#lp-lc-overlay").fadeTo(500, lcOverlayOpacity);	
							} else {
								$("#lp-lc-overlay").css("opacity", lcOverlayOpacity);
							}
					}
					
					// style of content
					var contentStyle = "position: fixed; top: 50%; left: 50%; width: 50px; height: 50px; margin-left: -25px; margin-top: -25px; z-index: 100;";
					
					// ABFRAGE IE 6.0 muss eingebaut werden
					// add content div to html body
					$("body").append("<div id=\"lp-lc-content\" style=\"" + contentStyle + "\"></div>");
					
					$.get(lcURL, {}, function(data, textStatus) {
						// if lcTitle is set adding a header + title to content
						if( lcTitle )
							$("#lp-lc-content").append("<div id=\"lp-lc-head\" style=\"display: none;\"><h3>" + lcTitle + "</h3><a href=\"javascript: ;\" title=\"" + lcCloseText + "\">x</a><div style=\"clear: both\"></div></div>");
						
						$("#lp-lc-content").append("<div id=\"lp-lc-load\"></div>");
						$("#lp-lc-load").append( data );
						$("#lp-lc-head a").click(CloseLightContent);
						$("#lp-lc-load").css("display", "none");
						
						var nWidth = $("#lp-lc-load").width();
						var nHeight = ($("#lp-lc-load").height() + $("#lp-lc-head").height());
						
						$("#lp-lc-content").animate({ width: nWidth, height: nHeight, marginLeft: "-" + ( nWidth / 2 ), marginTop: "-" + ( nHeight / 2 ) }, 500, "linear", function(){ $("#lp-lc-load").fadeIn(); $("#lp-lc-head").fadeIn(); });
					});
				}
				
			});
		});  
	};  
})(jQuery); 