/**
 * Name: TrackMate - common-utils.js
 * Version: 0.1 
 * Author: Sjoerd 
 * Goal: Provides utilities to be used all over the site.
 */
var TM = TM || {};
TM.Utils = TM.Utils || {};






TM.Utils.settings = {
	MSG_DISPLAYTIME : 5000,// milliseconds to display a message
    DEF_CONTENT_CONTAINER_SELECTOR : '.rightCol'
};







/**
 * Shows messages in the notification-bar
 * @param {string}	must be a property of the "txt"-object
 * @param {object} optional (object literal)
 *		msg			{array}	    array of text-messages
 *		containerEl	{object}	element where to place the notification
 *		where		{string}	where in the containerEl is the notification placed (bottom/top=default)
 *		warn		{boolean}	the message is a warning
 *		msgDisplTime{int}		milliseconds to display a message in the notificationbar
 * @return void
 */
TM.Utils.Notify = function(opts) {
	var opts			 = opts || {};
	opts.where			 = opts.where || 'top';
	opts.msgDisplTime	 = opts.msgDisplTime || TM.Utils.settings.MSG_DISPLAYTIME;
	var containerEl		 = (opts.containerEl) ? $j(opts.containerEl) : $j(TM.Utils.settings.DEF_CONTENT_CONTAINER_SELECTOR);
	
	if( !containerEl ) return;
    
    var msgEl = $j('<ul/>');
    msgEl.addClass((opts.warn) ? 'errorlist' : 'notifylist');
    // populate
    var msgLen = opts.msg.length;
    for(var i=0; i<msgLen; i++)
        msgEl.append('<li>'+opts.msg[i]+'</li>')
    
    // add to DOM
    msgEl.hide();
    if( opts.where == 'top' )
        containerEl.prepend( msgEl );
    else
        containerEl.append( msgEl );
    
    msgEl.fadeIn('slow', function(){
		setTimeout(function() {
			msgEl.fadeOut('slow', function(){
                msgEl.remove();
            });
		},opts.msgDisplTime)
    });
};

/*
$j( function(){
    TM.Utils.Notify({
        msg : [
            'hi #1',
            'hi #2'
        ]
    });
} )
*/

