(function($){
	$.fn.extend({
		b5280Modal: function() {
			//Create our overlay object
			var overlay = $("<div id='overlay'></div>");
			//Define our modal window
			var modalWindow = $("#videoModal");
			//modalWindow.hide();
			// Bind all links and inputs with class 'close-modal' the modalHide()
			return this.each(function() {
				//Listen for clicks on objects passed to the plugin
				$(this).click(function(e) {
					// find the height of the page.
					var pos;
					pos = findPos('findCenter');
					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);
					overlay.css({"opacity": 0.8});
					overlay.fadeIn(1000);
					
					//Prevent the anchor link from loading
					e.preventDefault();
					
					//Activate a listener 
					$(document).keydown(handleEscape);	
					modalWindow.css({'top': pos[0], 'left':pos[1]}).fadeIn(1000);
					$('.close-modal, #overlay').click(function(e) {e.preventDefault(); modalHide();});
				});
			});
			
			//Our function for hiding the modalbox
			function modalHide() {
				$(document).unbind("keydown", handleEscape)
				var remove = function() { $(this).remove(); };
				overlay.fadeOut(remove);
				modalWindow.fadeOut(300);
			}
			
			//Our function that listens for escape key.
			function handleEscape(e) {
				if (e.keyCode == 27) {
					modalHide();
				}
			}
			function findPos(obj) {
				var curleft = curtop = 0; 
				if(obj == 'findCenter') {
				curtop = ($(window).height())/2 - (modalWindow.height()/2)+$(window).scrollTop() -30;
				curleft = ($(window).width()/2) - (modalWindow.width()/2)+$(window).scrollLeft();
				} else {
					if (obj.offsetParent) {
						do {
								curleft += obj.offsetLeft;
								curtop += obj.offsetTop;
						} while (obj = obj.offsetParent);
					}
				}
				return [curtop,curleft];
			}
		}
	});
})(jQuery);