(function($){
	$.fn.extend({
		modalPanel: function() {
			
			//Create our overlay object
			var overlay = $("<div id='modal-overlay'></div>");
			//Create our modal window
			var modalWindow = $("<div id='modal-window'></div>");
			
			var modalData = $("<div id='modal-data'></div>");
			
			return this.each(function() {
				//Listen for clicks on objects passed to the plugin
				$(this).click(function(e) {
					
					if (typeof document.body.style.maxHeight === "undefined") { //if IE 6
						$("body","html").css({height: "100%", width: "100%"});
						$("html").css("overflow","hidden");
					}
					
					//Append the overlay to the document body
					$("body").append(overlay.click(function() { modalHide(); }))
					//Add a loader to our page
					$("body").append("<div id='modal-load'></div>");
					
					//Set the css and fade in our overlay
					overlay.css("opacity", 0.8);
					overlay.fadeIn(150);
					
					//Prevent the anchor link from loading
					e.preventDefault();
					
					//Activate a listener 
					$(document).keydown(handleEscape);	
					
					//Load the content
					$.get(this.href, function(data){
						<!--- alert("Data Loaded: " + data); --->
						var imageWidth = 880 / 2 ;
						var imageHeight = 500 / 2;
						
						modalWindow.css({
							"margin-left": -imageWidth,
							"margin-top": -imageHeight
						});							
						
						modalData.css('overflow','auto');
						
						$("#modal-load").remove();

						var modalClose = "<a href='#' class='close' id='modalClose'><img src='/images/global/icon_cross_on.png'  /></a>";

						modalData.html(data);
						modalWindow.append(modalData);
						modalWindow.append(modalClose);
						$("body").append(modalWindow);
												
						modalWindow.fadeIn(150);

						$('a[class=close]', modalWindow).bind('click',function(){
							modalHide();
							return false;
						});
						
						modalData.jScrollPane({showArrows:true, reinitialiseOnImageLoad:true});	
					});
				});
			});
			
			//Our function for hiding the modalbox
			function modalHide() {
				$('#modal_data').jScrollPaneRemove();	
				$(document).unbind("keydown", handleEscape)
				var remove = function() { $(this).remove(); };
				overlay.fadeOut(remove);
				modalData.jScrollPaneRemove();
				modalData.html('');
				modalWindow
					.fadeOut(remove)
					.empty();
			}
			
			//Our function that listens for escape key.
			function handleEscape(e) {
				if (e.keyCode == 27) {
					modalHide();
				}
			}
		}
	});
})(jQuery);
