/**
 * Add a notification bar to the screen
 */
(function($) {
    var jbartimeout = false;
    $.bar = function(options) {
        var defaults = {position: 'top', time: 0, click_to_close:true};
        options = $.extend(defaults, options);
        if ($('.jbar').length) { $.removebar(); }
        if(options.time){jbartimeout = setTimeout('$.removebar()', options.time);}
        var _message_span = $(document.createElement('div')).addClass('jbar-content').append(options.message);
        var _wrap_bar = $(document.createElement('div')).append(_message_span);
        (options.position == 'bottom') ? _wrap_bar.addClass('jbar jbar-bottom') : _wrap_bar.addClass('jbar jbar-top');
        if(options.click_to_close){_wrap_bar.css({ "cursor": "pointer" }).click(function(e) { $.removebar(); });}
        $('body').append(_wrap_bar);
    };
    $.removebar = function(txt) {
        if ($('.jbar').length) {
            if(jbartimeout){clearTimeout(jbartimeout);}
            $('.jbar').fadeOut('fast', function() {
                $(this).remove();
            });
        }
    };
})(jQuery);

