﻿(function ($) {
    $.fn.notifyMe = function (options) {
        // Defaults Options
        var defaults = {
            message: "",
            speed: 1000,
            closeSpeed: 500,
            backgroundColor: "#F9EDBE",
            align: "center",
            color: "#000",
            borderColor: "#F0C36D"
        };

        $notice = $(this);
        options = $.extend(defaults, options);

        if (options.message != "") {
            // Mounting structure
            $notice.css("background-color", options.backgroundColor);
            $notice.css("border-color", options.borderColor);
            $notice.css("color", options.color);
            $notice.addClass("ui-corner-all notifyMe");
            $notice.html("<div id='message'></div><span class='ui-icon ui-icon-close'></span>");
            $notice.find("#message").html("<span class='ui-icon ui-icon-info icon'></span>" + options.message);

            if (options.align == "center") {
                $notice.css("left", ($notice.parent().width() / 2) + "px");
                $notice.css("margin-left", "-" + ($notice.width() / 2 + 20) + "px");
                $notice.find(".ui-icon-close").css("margin-left", ($notice.width() / 2 + 4) + "px");
            }

            // Button Close
            $notice.find(".ui-icon-close").click(function () {
                $message = $(this).parent();
                $notice.fadeOut(options.closeSpeed).find($message).remove();
            });

            $(this).fadeIn(1000);
            $notice.css("display", "table");
            var destination = $(this).offset().top;
            $("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination }, options.speed, function () {
                window.location.hash = this
            });
        }
        else {
            $notice.hide();
        }
    };
})(jQuery);
