/**
 * StarLight - A client side webpage framework
 *
 * @package StarLight
 * @author Icewind <icewind (at) derideal (dot) com>
 * @copyright 2009
 * @license http://www.gnu.org/licenses/gpl.html GNU Public License
 * @url http://blacklight.metalwarp.com/starlight
 * @version 0.1
 */

SLNotification=function(text,time){
	this.text=text;
	this.time=(time)?time:0;
	this.notify();
}

SLNotification.prototype={
	notify:function(){
		this.holder=document.getElementById('SLNotificationHolder');
		if (!this.holder){
			this.holder=document.createElement('div');
			this.holder.className='SLNotificationHolder';
			this.holder.setAttribute('class','SLNotificationHolder');
			this.holder.setAttribute('id','SLNotificationHolder');
			document.getElementsByTagName('body')[0].appendChild(this.holder);
		}
		this.notification=document.createElement('div');
		this.animator=new SLAnimator(this.notification,'fade');
		this.notification.className='SLNotification';
		this.notification.setAttribute('class','SLNotification');
		if (document.documentElement.innerHTML){
			this.notification.innerHTML=this.text;
		}else{
			var text=document.createTextNode(this.text);
			this.notification.appendChild(text);
		}
		this.holder.insertBefore(this.notification,this.holder.firstChild);
		this.animator.from=0;
		this.animator.to=0.9;
		this.animator.run();
		mainEventHandler.addListner(this.notification,this.removeNotification,'onclick',this);
		if (this.time>0){
			this.timer = new SLTimer(this.removeNotification, this.time,false,this);
		}
	},
	removeNotification:function(){
		this.animator.from=0.9;
		this.animator.to=0;
		this.animator.onfinish=new callBack(function(){this.holder.removeChild(this.notification);},this);
		this.animator.run();
	}
}

function renderNotifications(){
	notifications=document.getElementsByTagName('div');
	for(var i=0;i<notifications.length;i++){
		notification=notifications[i];
		if(notification.className=='sl_notificationNode'){
			var text=(notification.innerHTML)?notification.innerHTML:notification.textContent;
			var time=(notification.getAttribute('time'))?notification.getAttribute('time')*1000:0;
			new SLNotification(text,time);
		}
	}
}

mainLoadStack.append(renderNotifications);