var notificationWrapperSelector = notificationWrapperSelector   || '#notification-wrapper';
var notificationSelector        = notificationSelector          || '#notification';
var notification;

$(function() {
    notification = {
        timer: null,
        defaultDuration: 2000,
        wrapper:    $(notificationWrapperSelector),
        box:        $(notificationSelector),
        
        //messageClass is the CSS class to give to the notification: see notifications.css for defined classes.
        //duration is the number of milliseconds before the notification hides itself (default 2000);
        //pass -1 to have the message stay indefinitely.
        show: function(message, messageClass, duration)
        {
            var t=this;
            t.box.text(message);
            t.box.attr("class", messageClass);
            t.wrapper.slideDown("fast");
        
            if (!duration) duration = t.defaultDuration;
            
            if (duration != -1) t.hideAfter(duration);
            else t.cancelTimer();
        },
        
        hide: function()
        {
            this.cancelTimer();
            this.wrapper.slideUp("fast");
        },

        cancelTimer: function() { clearTimeout(this.timer); this.timer = null; },
        hideAfter: function(duration)
        {
            var t=this;
            t.cancelTimer();
            t.timer = setTimeout(function() { t.hide() }, duration);
        }
    };
});