(function($) {
    $.fn.extend({
        modalPanel: function(message) {

            if (!message) {
                message = 'Daten werden geladen...';
            }

            function modalHide() {
                $(document).unbind("keydown", handleEscape);
                var remove = function() { $(this).remove(); };
                overlay.fadeOut(remove);
                modal.fadeOut(remove).empty();
            }

            function handleEscape(e) {
                if (e.keyCode == 27) {
                    modalHide();
                }
            }

            var overlay = null;
            var modal = null;

            if ($("#modal_overlay").length > 0) {
                overlay = $("#modal_overlay");
                modal = $("#modal_load");
                modal.find('p:first').html(message);
            }
            else {
                overlay = $('<div id="modal_overlay"></div>');
                modal = $('<div id="modal_load"><p class="text wait">' + message + '</p></div>');
                $("body").append(overlay);
                $("body").append(modal);
            }

            return this.each(function() {
                $(this).submit(function(e) {
                    if (typeof document.body.style.maxHeight === "undefined") { //if IE 6
                        $("body", "html").css({ height: "100%", width: "100%" });
                    }

                    modal.show();
                    overlay.css("opacity", 0.4);
                    overlay.show();

                });
            });
        }
    });

})(jQuery);