﻿//This is a private jQuery plugin developed by Ahmed Galal (someone_survive@hotmail.com)
//Used for showing confirmation messages and other message types

(function ($) {
    var config = {
        message: '',
        type: 2,
        selector: '.messageBox'
    };

    var methods = {
        config: function (options) {
            if (options) {
                $.extend(config, options);
            }
        },
        show: function (options) {
            var messageHtml = "<div class='message " + methods.getMessageType(options.type) + "'><p>" + options.message + "</p></div>";

            this.slideDown();
            this.fadeOut();
            this.html(messageHtml);
            return this.fadeIn();
        },
        hide: function () {
            return $(this).slideUp("slow");
        },
        destroy: function () {
            return $(this).html("");
        },
        getMessageType: function (type) {
            if (typeof type == 'number') {
                switch (type) {
                    case 0:
                        return "warning";
                    case 1:
                        return "error";
                    case 2:
                        return "success";
                    case 3:
                        return "info";
                    default:
                        return "info";
                }
            }
            else
                return type;
        }
    };
    jQuery.message = function (options) {
        if (options) {
            $.extend(config, options);
        }

        if (methods[options]) {
            return methods[options].call($(config.selector), config);
        }
        else if (typeof options == 'object' || !options) {
            return methods.show.call($(config.selector), config);
        }
        else {
            $.error("Method " + options + " are not supported in the message plugin");
        }
    }
    jQuery.fn.message = function (options) {

        if (options) {
            $.extend(config, options);
        }

        if (methods[options]) {
            return methods[options].call(this, config);
        }
        else if (typeof options == 'object' || !options) {
            return methods.show.call(this, config);
        }
        else {
            $.error("Method " + options + " are not supported in the message plugin");
        }
    }
})(jQuery);
