(function($){
	$.fn.extend({
		contactusPanel: function() {
			
			//Create our overlay object
			var overlay = $("<div id='modal-overlay'></div>");
			//Create our modal window
			var modalWindow = $("<div id='modal-window'></div>");
			
			var windBody = $("body");

			var closeButton = $("<div style='border:0; position:absolute; margin-left:-15px; margin-top:-15px;' align='right'><img src='images/closeButton.gif' width='30' height='30' border='0' /></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
					windBody.append(overlay.click(function() { modalHide(); }))
					//Add a loader to our page
					windBody.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);	
					
					var imageWidth = 800 / 2 ;
					var imageHeight = 570 / 2;
					modalWindow.css({
						"margin-left": -imageWidth,
						"margin-top": -imageHeight
					});	
					modalWindow.append(closeButton.click(function() { modalHide(); }))
					modalWindow.append("<iframe id='iView' style='width:800px; height:570px; background-color:#000000;' src='contactus_form.asp'></iframe>");
					$("body").append(modalWindow);
					modalWindow.fadeIn(150);
					
				});
			});
			//Our function for hiding the modalbox
			function modalHide() {
				$(document).unbind("keydown", handleEscape);
				var remove = function() { $(this).remove(); }
				overlay.fadeOut(remove);
				modalWindow
					.fadeOut(remove)
					.empty()
			}
			
			//Our function that listens for escape key.
			function handleEscape(e) {
				if (e.keyCode == 27) {
					modalHide();
				}
			}
		}
	});
})(jQuery);
