(function($) {
	 
	
	
	$.fn.fwindow = function(){
		
		var i = 0;
			
		   	return $(this).each(function(){
		   		
				var c = {
					"i" : i,
					"id" : $(this).attr("id"),
					"offset" : $(this).offset(),
					"width" : $(this).innerWidth()
				};
			
				var fwindow;
				var fwindow_background;
				var fwindow_element;
				var fwindow_title;

				// Event
				$(this).click(open_window);
			
				function open_window() {
					
					// Floating window
					fwindow = document.createElement("div");
					fwindow.setAttribute("id", "fwindow");
					
					// Floating window background
					fwindow_background = document.createElement("div");
					fwindow_background.setAttribute("id", "fwindow_background");
					$(fwindow_background).click(close_window);
					
					$(fwindow_background).css({
						/*"background-color" : "#000000",*/
						"position" : "absolute",
						"height" : $(document).height(),
						"left" : "0px",
						"top" : "0px",
						"width" : "100%",
						"z-index" : "1",
						"opacity" : "0.2"
					});
						
					// Floating window header
					$(fwindow).append(fwindow_header());
					
					// Content
					fwindow_element=$("."+$(this).attr("id")).html();
					
					// Add window element
					$(fwindow).append(fwindow_element);
					
		   			// Add window background
		   			$("body").append(fwindow_background);
					
					// Show window
					$("body").append(fwindow);
					
		   			$(fwindow).center();
				
				};
				
				function close_window() {	
			
					$(fwindow).remove();
					$(fwindow_background).remove();
				
				}
				
				function fwindow_header() {
					var div = document.createElement("div");
					div.appendChild(clsBtn());
					$(div).css({"width" : "100%", "padding" : "0px", "text-align" : "right", "background-color" : "#6699CC"});
					
					return div;
					
				};
				
				function clsBtn() {
					
					// Close button
					var clsBtn = document.createElement("input");
					clsBtn.setAttribute("type", "button");
					clsBtn.setAttribute("value", "x");
					$(clsBtn).bind("click", close_window);
					
					return clsBtn;
					
				}
				
				jQuery.fn.center = function () {
				    this.css("position","absolute");
				    this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
				    this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
				    return this;
				}
				
				i++;
				
		   });
		       
	};
	 
})(jQuery);