var Notifier = new Class({
	initialize:function(page){
		this.page = page;
		this.notificationBox = new Element('div',{'class':'notificationBox'}).inject(this.page.container);
// 		this.notificationBox.addEvent('clear',function(){this.notificationBox.set('html','');}.bindWithEvent(this));
		this.notes = new Array();
	},
 	
 	getNoteId: function(){
		return this.notes.length;
	},

	showNote: function (title,text,type){
		var id = this.getNoteId();
		var note  = this.createNotification(id,title,text,type);
		
		var notey = new Fx.Slide(note,{ 
						onComplete: function(){
							if(this.notes.length == 0)
								this.notificationBox.set('html','');
						}.bindWithEvent(this)
		});
		notey.show();
		notey.slideIn('horizontal');
		notey.set('id','notey_' + id);
		this.notes.include(notey);
		this.deleteNote.delay(3000,this,[notey]);
	},

	createNotification: function(id,title,text,type){
		
		var notification = new Element('notification',{'id':'notey_' + id }).inject(this.notificationBox);
		var notetitle = new Element('div',{'class':'noteTitle','text':title}).inject(notification);
		var notetext = new Element('pre',{'class':'noteText','html':text}).inject(notification);
		
		if(!type)
			return notification;
		
		switch(type){
			case "info": 	return notification;
			case "error":	notetitle.setStyle('color','red');return notification;
			default:		return notification;
		}
		return notification;
	},

	deleteNote: function(note){
		this.notes.erase(note);
		note.slideOut();
	},
});
