var hot_flash = function ( text, duration ) {
	 $('alert_box_message').set('html', text);
	 if( ! duration ) {
		 $('alert_box').fireEvent('open');
	 } else {
		 $('alert_box').fireEvent('open_close', duration );
	 }
}

var alert_running = false;

window.addEvent('domready', function() {
    var alert_open = new Fx.Morph($('alert_box'), { link: 'ignore', transition: 'quad:in:out' });
    var alert_fade_in;
    var alert_fade_out;
    if ( $('alert_box') ) {
	    $('alert_box').addEvents({
	    	
	        'open': function() { 
	    		alert_running = true;
	    		alert_open.set('.alert_open');
	    		alert_open.start({opacity:[0,1]});
	        },
	        'close': function() {
	        	if( alert_running ) {
	        		alert_running = false;
	        		alert_open.set('.alert_close');
	        		alert_open.start( { opacity: [1,0] } );
	        	}
	        },
	        'open_close': function( ms ){  
	            alert_fade_in = new Fx.Morph($('alert_box'), { 
	            	link: 'chain', 
	            	transition:'quad:out',
	            	onComplete: function( ele ) {
	            		alert_fade_out.start( { opacity: [1,0] } );
	            	},
	            });
	            alert_fade_out = new Fx.Morph($('alert_box'), { 
	            	duration: ms, 
	            	link: 'chain', 
	            	transition:'quad:out',
	            	onComplete: function( ele ){
	            		alert_running = false;
	            		$('alert_head').className = '';
	            	}
	            });
	            
	            if( ! alert_running ){
	            	alert_running = true;
	            	$('alert_head').className = 'close_alert_head';
	            	alert_fade_in.set('.alert_fade_open').start( { opacity: [0,1] } );
	            }
	        }
	    });	
    }

    window.addEvents({
			keydown: function() {
    			if ( $('alert_box') ) {
    				$('alert_box').fireEvent('close');
    			}
			},
	});
    
    if ( $('alert_box') ) {
	    $('alert_box_x').addEvents({
	    	click: function(e) { e.stop();
	    		$('alert_box').fireEvent('close');
	    	}
	    });
    }
    
});
