var Flash = {
	//pull those pesky messages from the cookies.
    fromCookies: function(){
        var data = JSON.parse(unescape(Cookie.get("flash")));
		 Cookie.erase("flash");
        if (data) {
			if (data['error']) {setTimeout(function() {Flash.error(data['error'].toString().gsub(/\+/, ' '))}, 0.2)}
			if (data['notice']) {setTimeout(function() {Flash.notice(data['notice'].toString().gsub(/\+/, ' '))}, 0.2)}
		} 
    },
    // When given an error message, wrap it in a list 
    // and show it on the screen.  This message will auto-hide 
    // after a specified amount of miliseconds
    error: function(message){
        $('flash-errors').innerHTML = '';
        $('flash-errors').innerHTML = "<li>" + message + "</li>";
        new Effect.Appear('flash-errors', {
            duration: 0.3
        });
        setTimeout(Flash.fadeError.bind(this), 5000);
    },
    
    notice: function(message){
        $('flash-notice').innerHTML = '';
        $('flash-notice').innerHTML = "<li>" + message + "</li>";
        new Effect.Appear('flash-notice', {
            duration: 0.5
        });
        setTimeout(Flash.fadeNotice.bind(this), 5000);
    },
	
	dialog: function(innerHTML) {
		$('flash-dialog').innerHTML = '';
        $('flash-dialog').innerHTML = "<a href='#' onclick='Flash.fadeDialog()'><img src='/images/template/thumbdown.png'></img></a><li>" + innerHTML.replace(/REMOVE_THIS/g, '') + "</li>";
        new Effect.Appear('flash-dialog', {
            duration: 0.5
        });
	},
	
	dialogFromDiv: function(id) {
		Flash.dialog($(id).innerHTML)
	},
    
    // Responsible for fading notices level messages in the dom    
    fadeNotice: function(){
        new Effect.Fade('flash-notice', {
            duration: 0.5
        });
    },
    
    // Responsible for fading error messages in the DOM
    fadeError: function(){
        new Effect.Fade('flash-errors', {
            duration: 0.5
        });
    },
	
	// Responsible for fading error messages in the DOM
    fadeDialog: function(){
        new Effect.Fade('flash-dialog', {
            duration: 0.5
        });
    }
}