core.feedback = { dom: ".form-messages-box", inited: false, lang: "" }; 
core.feedback.set_lang = function(){
	core.feedback.lang = sessvars.site.active_locale;
	return core.feedback.lang;
};

core.feedback.init = function(){
	var html = "<div class='form-messages-box' style='display:none'><a class='close' href='#'>Cerrar</a><div style='clear: both;'></div><div class='messages-panel'></div>	</div>";
	
	$('#feedback').html(html);
 	$(core.feedback.dom).find('.close').click( function(e){			
		core.feedback.toggle({html:" ", show:false });
		//Obligamos a incicializarse con el link en desactivado
		$(core.feedback.dom).find('.close').hide();

		return false;
	});
	
	core.feedback.inited = true;
	
	//Obligamos a incicializarse con el link en desactivado
	$(core.feedback.dom).find('.close').hide();

};


//Se debepasar siempre una opctión de .show con la finaliad de poder controlar que se muestra o no 
core.feedback.toggle = function(options){
	var options = options || {};
	var box = $(core.feedback.dom+":first");
	var msg_panel = box.find('.messages-panel');
	var html_msg = null;
	
	msg_panel.html("");
	
	if ( options.cls != null ){
		var e = box.find('.messages-panel');
		e.removeClass('error warn notice');
		e.addClass( options.cls );
	}
	if ( options.x != null ){
		box.css('left',options.x);
	}
	if ( options.y != null ){
		box.css('top',options.y);
	}
	
	var show_message = function(){
		if ( options.close != null ){
			if ( options.close ){
				box.find('.close').show();
			}else{
				box.find('.close').hide();
			}
		}else{
			box.find('.close').hide();
		}
	
		if ( options.html != null ){
			msg_panel.html(options.html);
		}else{
			if(core.feedback.lang == "es") {
				html_msg = 'Por favor espere';
			}else if(core.account.lang == "en") {
				html_msg = 'Please wait';
			}
			msg_panel.html(html_msg);
			
		}
		
		if ( options.afterShow != null ){
			options.afterShow(box);
		}
		box.data('opened',true);
	}	

	if ( options.show ){
		
		box.slideDown().show('slow');		
		show_message();
	
	}else{
		
		box.slideUp().hide('slow');
		box.data('opened',false);
	}
};
