﻿/*
* 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.1
*
* Project home:
* http://www.dmitri.me/blog/notify-bar
*/

/**
* param Object
*/


_overlay = function(status) {
    switch (status) {
        case 'show':
            $.alerts._overlay('hide');
            $("BODY").append('<div id="popup_overlay" class="bgFramer"></div>');
            $("#popup_overlay").css({
                position: 'absolute',
                zIndex: 99998,
                top: '0px',
                left: '0px',
                right: '0px',
                bottom: '0px',
                background: '#000000',
                opacity: 0
            });
            $("#popup_overlay").animate({
                opacity: 0.8
            }, 400);
            break;
        case 'hide':
            $("#popup_overlay").animate({
                opacity: 0
            }, 400, function() {
                $("#popup_overlay").remove();
            });
            break;
    }
}


jQuery.notifyBar = function(settings) {

    (function($) {
        var tmClock = null;
        var bar = notifyBarNS = {};
        notifyBarNS.shown = false;

        if (!settings) {
            settings = {};
        }
        // HTML inside bar
        notifyBarNS.html = settings.html || "";

        //How long bar will be delayed, doesn't count animation time.
        notifyBarNS.delay = settings.delay || 4000;

        //How long notifyBarNS bar will be slided up and down
        notifyBarNS.animationSpeed = settings.animationSpeed || 500;

        //Use own jquery object usually DIV, or use default
        notifyBarNS.jqObject = settings.jqObject;

        //Set up own class
        notifyBarNS.cls = settings.cls || "";

        if (notifyBarNS.jqObject) {
            bar = notifyBarNS.jqObject;
            notifyBarNS.html = bar.html();

        } else {
            bar = $('<div id="nBarContainer" style="position:absolute;"></div>')
      .addClass("jquery-notify-bar")
      .addClass(notifyBarNS.cls)
      .css('position', 'absolute')
      .attr("id", "__notifyBar");
        }

        var containers = '<div class="notifybartop"><input type="button" id="btnclosenotifybar" value="" class="btnclosenotifybar" /></div> <div class="notifybarmiddle"><p>' + notifyBarNS.html + '</p></div><div class="notifybarbottom"></div>'

        bar.html(containers);


        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');
        {
            clearTimeout(tmClock);

            $('.jquery-notify-bar').remove();

            $("body").prepend(bar);
            _overlay('show');


            $("#btnclosenotifybar").click(function() {
                $('#' + id).animate({ opacity: 0 }, asTime, function() { $('#' + id).remove() });
                _overlay('hide'); 
            });
        }



        var windowTop = ($(window).height() / 2) - (bar.height() / 2);


        bar.css({ top: windowTop });
        bar.animate({ opacity: 1 }, asTime);

        tmClock = setTimeout("_overlay('hide'); $('#" + id + "').animate({ opacity: 0 }, " + asTime + ", function() {$('#" + id + "').remove()});", notifyBarNS.delay + asTime);






    })(jQuery)
};
