/**
 * Utility class to display messages
 *
 * @author avergara
 */
var MessagesInternal = Class.create({
	initialize: function() {
		
	},
  	
  	/**
  	 * The begin and end colors for effects for the different message box types
  	 */
	effectsColors: {
		errorBox:{
			begin:"#F85C63",
			end:"#FEECEC"
		}
	
	},
	
	/**
  	 * Displays a message box of the given type with the given message
  	 * @param boxType the type of the message box to display
  	 * @param messsage the message to display
  	 */
	showMessageBox: function (boxType, message) {
		this.clearMessageBox(boxType);
		var box = ($$('[class~="' + boxType + '"]'))[0];
		var parent = (box.ancestors())[0];
		if(box == undefined) return;

		box.innerHTML = message;
		parent.show();
		
		box.id = "message";//tests look for this id to get the message
		
		if(this.effectsColors[boxType] != undefined){
			new Effect.Morph(parent, {style: 'background-color:'+ this.effectsColors[boxType].begin +';',duration: 0.2});
			new Effect.Morph(parent, {style: 'background-color:'+ this.effectsColors[boxType].end +';',duration: 2, queue: 'end'});
		}
	},			

	/**
  	 * Removes a specific message from the page
  	 */
	clearMessageBox: function(boxType) {
		var box = ($$('[class~="' + boxType + '"]'))[0];
		
		if(box == undefined) return;
		
		box.innerHTML = "";
	}, 
	
	/**
  	 * Removes all messages from the page
  	 */
	clearAllMessageBoxes: function() {
		var box = ($$('[class~="message-div"]'));
		
		if(box == undefined) return;
		
		box.each(function(div, index) {
			var parent = (div.ancestors())[0];
			div.innerHTML = "";
			div.id = Math.ceil(Math.random()*100000000);
			parent.hide();
		});
	} 
});


var Messages = new MessagesInternal();