(function($){
	$.fn.extend({
		modalPanel: function() {
			
			//Check to see if the modalpanel has been disabled.
			var hideCookie = readCookie("modalPanel");
			if (hideCookie == null) {
			
				//Create our overlay object
				var overlay = $("<div id='modal-overlay'></div>");
				
				return this.each(function() {
						
					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();
					}));
					
					
					$("#modal-window").each(function() {
						$("a.modal_hide_btn").click(function(e) {
							e.preventDefault();
							modalHide();
						});
					});
					
					
			
					//Set the css and fade in our overlay
					overlay.css("opacity", 0.9);
					overlay.fadeIn(150);
					
					

					$("#modal-window").css({
						"margin-left": -417,
						"margin-top": -250
					});
					
					
					$("#modal-window").fadeIn(150);
				});
			}
			
			//Our function for hiding the modalbox
			function modalHide() {
				
				//Creating cookie to hide the modalPanel
				$("#modal-window").each(function() {
					$('input:checkbox').each( function() {
						if (this.checked) {
							//Set the cookie to hide the modal panel for the session.
							createCookie('modalPanel','hide',180);
						}
						else {
							//Set the cookie to hide the modal panel for 1 year.
							createCookie('modalPanel','hide',0);
						}
					});
				});
				
				var remove = function() { $(this).remove(); };
				overlay.fadeOut(remove);
				$("#modal-window")
					.fadeOut(remove)
					.empty();
			}
				
		}
	});
})(jQuery);



