/* 
 * Bologna Iperbole
 *
 * @package		Iperbole
 * @author		Oskar Krawczyk (o.krawczyk@keepthinking.it)
 * @version		1.0
 * @dependecies	MooTools 1.2+
 * @copyright	Copyright (c) 2009-2010, Oskar Krawczyk (Keepthinking Ltd.)		
 * @link		http://keepthinking.it
 * 
 ======================================================================= */

var Notify = new Class({
	
	Implements: [Events],
	
	notifier: false,
	
	create: function(){
		this.notifier = new Element('div', {
			'class': 'notifier_body',
			'styles': {
				'opacity': 0.8
			}
		}).inject($(document.body));
	},
	
	setTimer: function(){
		
		// set the timer of the delay
		this.notifier.timer = (function(){
			this.hide();
		}).delay(6000, this);
		
		// manage the timer on user input
		this.notifier.addEvents({
			mouseenter: function(){
				
				// clear the timer
				this.stopTimer();
			}.bind(this),
			
			mouseleave: function(){
				
				// restart the timer
				this.setTimer();
			}.bind(this),
			
			click: function(){
				
				// hide the message and clear the timer
				this.hide();
			}.bind(this)
		});
	},
	
	stopTimer: function(){
		$clear(this.notifier.timer);
	},
	
	show: function(content, messageType){
		
		// create the notifier elements if they don't exsit
		if (!this.notifier){
			this.create();
		}
		
		// set the message type and text
		this.notifier.set({
			'html': content,
			'class': 'notifier_body ' + messageType
		}).show();
		
		// create the timer
		this.setTimer();
	},
	
	hide: function(content){
		this.notifier.fade(0);
		this.stopTimer();
	},
	
	warning: function(content){
		this.show(content, 'warning');
	},
	
	message: function(content){
		this.show(content, 'message');
	},
	
	toElement: function(){
		return this.notifier;
	}
});

var Notifier = new Notify();
