/**
 * Copyright (c) 2009 Urh Srecnik <urh@srecnik.info>
 * 
 * Built on top of jQuery library:
 *   http://jquery.com/
 *
 * */

/**
 * Displays message on top of the page
 * @param string message to display
 * @param string type of the message (must be one of: 'info', 'warning', 'error')
 * */
jQuery.addMessage = function(message, type)
{
    // check type of the message
    var type_ok = false;
    var type_allow = new Array('info', 'warning', 'error');
    for (t in type_allow)
        if (type_allow[t] == type)
            type_ok = true;

    // if type is invalid fall back to 'warning'
    if (!type_ok) {
        type = 'warning';
        message = message + " [...]";
    }

    // increase global count of messages (for unique msg id)
    if (!jQuery.__messages__)
        jQuery.__messages__ = 0;
    jQuery.__messages__++;
    
    // show the message
    var message_html = '<div id="msg-' + jQuery.__messages__ + '" class="msg-' + type + '">' + message + '</div><br/>';
    jQuery("#messages").append(message_html);

    // hide the message after 30 sec
    setTimeout(function() {
       jQuery("#msg-" + jQuery.__messages__).remove();
    }, 30000);
}

