/**
 * Script para criação de hint para o framework.
 * 
 * @copyright - Ministério da educação
 * @author - Equipe mecwork - Webysther.
 * @since - 2008
 * @version - 1.0.0
 * 
 * 1.0.0 - Versão inicial
 * 
 * @example - O tip pode ser usado em dois modos, um no jquery e outro como
 *          classe.
 * 
 * Assim não function :
 * 
 * Ex. 1 :
 * 
 * hint = new Hint();
 * 
 * hint.create(URL_ROOT + "img/falha.gif");
 * 
 * Ex. 2 : Nesse caso não funcionará o tip apenas pois não foi definido a
 * mensagem
 * 
 * hint = new Hint();
 * 
 * tip = new Tip();
 * 
 * hint.create(URL_ROOT + "img/falha.gif", tip);
 * 
 * Assim funciona :
 * 
 * Ex. 1 :
 * 
 * $("#nuCnpj2").hint(URL_ROOT + "img/falha.gif");
 * 
 * Ex. 2 :
 * 
 * tip = new Tip();
 * 
 * tip.message = "O campo não pode estar sem valor.";
 * 
 * $("#nuCnpj2").hint(URL_ROOT + "img/falha.gif", tip);
 * 
 * Ex. 3 :
 * 
 * hint = new Hint();
 * 
 * hint.create(URL_ROOT + "img/falha.gif", null, $("#nuCnpj2"));
 * 
 */

var Hint = function() {

	return {

		/**
		 * Constantes para a validação, por favor só crie novas constantes se
		 * realmente for necessário. Elas podem ser reescritas pois são
		 * constantes falsas. As constantes só podem ser criadas a partir da
		 * versão 1.5 do javascript e é necessário usar a sintaxe 'const
		 * variavel = "valor constante"'.
		 */
		image : {

			OK : URL_ROOT + "img/correto.gif",
			FAIL : URL_ROOT + "img/falha.gif"

		},
		/**
		 * Cria o hint.
		 * 
		 * @param string
		 *            image - Endereço da imagem que será usada para criar o
		 *            hint.
		 * @param object
		 *            tip - Um object do tipo Tip.
		 * @param object
		 *            obj - Objeto que será usado como referência para criação
		 *            do objeto.
		 */
		create : function(image, tip, obj) {
		
			obj = obj || this;
			image = image || false;

			try {

				tip = tip || new Tip();

			} catch (excessao) {

				try {

					console.log("Inclua a classe Tip para que o tip funcione!");
					console.info(excessao);

				} catch (excessao) {

				}

			}

			if (!image || !$(obj).isExists()) {

				return;

			}

			$("#hint-" + obj.attr("id")).remove();

			obj.after('<img id="hint-' + obj.attr("id") + '" align="top" src="'
					+ image + '" />');

			try {

				$("#hint-" + obj.attr("id")).tip(tip.message, tip.title,
						tip.background);

			} catch (excessao) {

				try {

					console.log("Inclua a classe Tip para que o tip funcione!");
					console.info(excessao);

				} catch (excessao) {

				}

			}

		}
		
		/**
		 * Remove o hint específico.
		 */
		,
		clear : function(obj) {

			obj = obj || this;
			
			if(!$(obj).isExists()){
				
				return;
				
			}
			
			$("#hint-" + obj.attr("id")).remove();

		}

	}

}

jQuery.fn.extend({
	hint : new Hint().create
});
