// Bark - version 0.0.1
//
// Bark is a javascript library that performs Growl-style (music video) notifications for your
// website.
//
// Author: Brian Smith (bsmith@einsteinindustries.com)
//
// Requirements:
//
//     Prototype (>= 1.6)
//     Scriptaculous (>=1.8)

var Bark = {
    
    // Constants for setting the type of message
    //
    INFO: "info",
    SUCCESS: "success",
    ERROR: "error",
    
    // Default values for Bark options
    //
    defaultOptions: $H({
        'duration':   3.0,
        'message_class': null,
        'container_class': null,
        'type': null
    }),
    
    // Display a new notification.
    //
    // Options:
    //
    //      duration - The amount of time (in seconds) that the notification should display for.
    //      class - The HTML/CSS class attribute for the notification container.
    //
    // Example:
    //
    //      new Bark.Notification("This is a bark notification", { duration: 2.0 });
    //
    Notification: function (msg, opts) {

        var message = msg;
        var options = Bark.defaultOptions.merge(opts);
        var eltContainer = null;
        var that = this;
        
        function containerClassString() {
            return [ 'bark_notification_container', options.get('container_class') ].join(' ');
        }
    
        function messageClassString() {
            return [ 'bark_notification_message', options.get('type'), options.get('message_class') ].join(' ');
        }
    
        function createContainer() {
            eltContainer = new Element('div', { 'class': containerClassString() });
            eltMessage = new Element('p', { 'class': messageClassString() }).update(message);
            eltContainer.appendChild(eltMessage);
            eltContainer.hide();
            document.body.appendChild(eltContainer);
        }
        
        function startNotification() {
            createContainer();
            showNotification();
            setTimeout(stopNotification, parseFloat(options.get('duration')) * 1000);
        }
        
        function stopNotification() {
            hideNotification();
        }
        
        function showNotification() {
            Effect.BlindDown(eltContainer);
        }
        
        function hideNotification() {
            Effect.BlindUp(eltContainer);
        }
        
        this.debug = function() {
            console.log("Message: " + message);
            console.log("Options: " + options);
            console.log("Message class: " + messageClassString());
            console.log("Container class: " + containerClassString());
        };
        
        // Create the notification
        //
        startNotification();
    }
    
};
