// JavaScript Document
//created by Marcone Ferreira Ramos 01/11/2011
//contact development@marconeramos.com
(function($){
//starts the function. the bmmessage takes the message. the dissappear decides if the message will disappear.
jQuery.fn.bmmessagebox=function(bmmessage, disappear){
	//gives a name to the element
var element=this;
//calls the function
applyMsg();
//starts the function
function applyMsg(){
	//shows the element. it's important in case the element is invisible
	$(element).show();
	//dis gets the true or false. if true, the element will disappear.
	var dis=disappear;
	//elval gets the variable
	var elval=bmmessage;
	//splits the eval. its important to get the message type (ok, error, attentio, information).
	var str=elval.split("!::");
	//this case get the first part of the splitted string, witch is the type.
	switch(str[0]) {
		// in case this is an error
		case 'error':
			// changes the element css
		
		 	// inserts the second part of the elval string whitch is the message
			$(element).html('<div class="error_message"><div class="bmsgbox_message"><img style="margin-right:5px;" src="/images/apps/bm/core/msgbox_error/error_icon.png" align="left">'+str[1]+'</div> <div class="bmsgbox_notebottomcorner"></div></div>');
			
			
		break;
		case 'ok': 
			// inserts the second part of the elval string whitch is the message
			$(element).html('<div class="bmsgbox_message">'+str[1]+'</div> <div class="bmsgbox_notebottomcorner"></div>');
			// changes the element css
			$(element).toggleClass(".error_message");
		break;
		
		case 'redirect': 
			window.location.href = str[1];
		break;
	}
	// checks if dis variable is true.
	if (dis==true) {
		//if it is, it will hide the message after 10 sencods, will take 2 seconds to fadeout.
		$(element).delay(10000).slideUp(2000);
	}
}
};
})(jQuery);
