// humanizedmessage
// by DanielSteigerwald on MooTools forum
// http://forum.mootools.net/viewtopic.php?id=6508

HumanizedMessage = new new Class({            
 
        initialize: function() {
            // privates
            var messageWidth = 560,
                attachEventsHnd,
                hideHnd,
                container = new Element('div', { 
                		'class': 'humanized',
                    style: 'position: fixed; z-index: 99999; width: ' + messageWidth + 'px; height: 80px; top: 200px; background-color: black; opacity: 0;',
                    opacity: 0 
                }),
                message = new Element('div', {
                    style: 'color: white; margin: 20px auto; padding: 0 20px; text-align: center; font: 16px "Lucida Grande", Arial, Helvetica, Verdana, sans-serif;',
                    opacity: 0 
                }).inject(container),
                // create fx
                fx = new Fx.Elements([container, message], {
                    duration: 800,
                    link: 'cancel',
                    onComplete: function() { container.style.top = '200px'; }
		        });
 
 					  container.setStyles(
		      	{
		      		position: 'fixed',
		      		'background-color': 'black',
		      		width: messageWidth + 'px',
		      		height: '80px',
		      		top: '200px',
		      		'opacity': 0
		      	});
		      	
		      	message.setStyles(
		      	{
		      		color: 'white',
		      		margin: '20px auto',
		      		padding: '0 20px',
		      		'text-align': 'center',
		      		font: '16px "Lucida Grande", Arial, Helvetica, Verdana, sans-serif'
		      	});
 
 
	        function show(text) {    
	            container.setStyle('left', (window.getWidth() / 2) - (messageWidth / 2));
	 
			 
	      	
                message.innerHTML = text;        
                fx.start({ 0: { opacity: [0, 0.8] }, 1: { opacity: [0, 1] } });		
                $clear(attachEventsHnd);
                $clear(hideHnd);
                attachEventsHnd = attachEvents.delay(1000);
                hideHnd = hide.delay(5000);
            }
 
            function attachEvents(){
                document.addListener('mousemove', hide);
                document.addListener('click', hide);
                document.addListener('keypress', hide);        
            }
 
            function hide() {
                // Remove message if mouse is moved or key is pressed
                document.removeListener('mousemove', hide);
                document.removeListener('click', hide);
                document.removeListener('keypress', hide);                		        		
                fx.start({'0': {'opacity': [0], 'top': [300] }, '1': {'opacity': [0] }});		                    
            }
 
            window.addEvent('domready', function() {
                container.inject($(document.body))                                		        
            });
 
            // public api
            this.show = show;
        }
    });