(function($) {
    $.modal = {
        id: "jQueryModal",
        fadeSpeed: 0,
        opacity: "",
        zIndex: "",
        backgroundColor: ""
    },
    $.modal.initialize = function(options) {
        if (options) {
            for (var propertyName in options) {
                if (typeof ($.modal[propertyName]).toString().toLowerCase() != "undefined" && propertyName != "id")
                    $.modal[propertyName] = options[propertyName];
            }
        }
    },
    $.modal.show = function(targetobj, options) {
        $.modal.initialize({
            fadeSpeed: 500,
            opacity: "0.7",
            zIndex: "2000",
            backgroundColor: "#000000"
        });
        if (options) $.modal.initialize(options);

        $.modal.hide(targetobj);

        $("#" + $.modal.id).remove();

        var modalDiv = document.createElement('div');
        modalDiv.setAttribute('id', $.modal.id);
        $(modalDiv).css({
            opacity: $.modal.opacity,
            zIndex: $.modal.zIndex,
            backgroundColor: $.modal.backgroundColor,
            position: "absolute",
            top: "0",
            left: "0",
            display: "none"
        });
        $(modalDiv).width($(document).width() - 5);
        $(modalDiv).height($(document).height() + 50);
        $(modalDiv).appendTo($(document.body));

        var obj = targetobj;
        if (!targetobj.show) obj = $(targetobj);

        obj.css({
            zIndex: "2001",
            top: ($(window).height() / 2) - (obj.height() / 2) + $(document).scrollTop(),
            left: ($(window).width() / 2) - (obj.width() / 2)
        });

        $("#" + $.modal.id).show();
        obj.show();
//        $("#" + $.modal.id).animate(
//            { opacity: $.modal.opacity },
//            $.modal.fadeSpeed,
//            function() { obj.show(); });
    },
    $.modal.hide = function(targetobj) {
        var obj = targetobj;
        if (!targetobj.hide) obj = $(targetobj);
        obj.hide();

        $("#" + $.modal.id).hide();
        
//        $("#" + $.modal.id).animate(
//            { opacity: 0 },
//            $.modal.fadeSpeed,
//            function() {  });
    }
})(jQuery);