/*
* Notify Bar - jQuery plugin
*
* Copyright (c) 2009-2010 Dmitri Smirnov
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/mit-license.php
*
* Version: 1.2.2
*
* Project home:
* http://www.dmitri.me/blog/notify-bar
*/

/**
* param Object
*/
jQuery.notifyBar = function (settings) {

    (function ($) {

        var bar = notifyBarNS = {};
        notifyBarNS.shown = false;

        if (!settings) {
            settings = {};
        }
        // HTML inside bar
        notifyBarNS.html = settings.html || "Your message here";

        //How long bar will be delayed, doesn't count animation time.
        notifyBarNS.delay = settings.delay || 2000;

        //How long notifyBarNS bar will be slided up and down
        notifyBarNS.animationSpeed = settings.animationSpeed || 200;

        //Use own jquery object usually DIV, or use default
        notifyBarNS.jqObject = settings.jqObject;

        //Set up own class
        notifyBarNS.cls = settings.cls || "";

        //close button
        notifyBarNS.close = settings.close || false;

        if (notifyBarNS.jqObject) {
            barMsg = notifyBarNS.jqObject;
            notifyBarNS.html = barMsg.html();
        } else {
            bar = jQuery("<div></div>")
            .addClass("jquery-notify")
            .addClass(notifyBarNS.cls)
            .attr("id", "__notifyBar");
            barMsg = jQuery('<div class="jquery-notify-bar"></div>');
            bar.append(barMsg);
        }

        barMsg.html('<span>' + notifyBarNS.html + '</span>');

        bar.hide();
        var id = bar.attr("id");
        switch (notifyBarNS.animationSpeed) {
            case "slow":
                asTime = 600;
                break;
            case "normal":
                asTime = 400;
                break;
            case "fast":
                asTime = 200;
                break;
            default:
                asTime = notifyBarNS.animationSpeed;
        }
        if (bar != 'object');
        {
            jQuery("body").prepend(bar);
        }

        // Style close button in CSS file
        if (notifyBarNS.close) {
            barMsg.append(jQuery("<a href='#' class='notify-bar-close'></a>"));
            jQuery(".notify-bar-close").click(function () {
                bar.stop().animate({ top: (0 - bar.height())-28 }, asTime, function () {
                    $(this).remove();
                });
                return false;
            });
        }

        // Position containder off-screen
        bar.css({ top: (0 - bar.height()) });
        //slide down using animation
        bar.show().animate({ top: 0 }, asTime, function () {
            $(this).delay(notifyBarNS.delay).animate({ top: (0 - bar.height())-28 }, asTime, function () {
                $(this).remove();
            });
        });

    })(jQuery)
};
