var plg_categoria_arvore = {
	"opSemArvore": "X",
	"opArvoreFechada": "]",
	"opArvoreAberta": "[",
	
	"classeSub": ".plg_categoria_arvore_sub",
	"classeMais": ".plg_categoria_arvore_mais",
	"classeItemOn": ".plg_categoria_arvore_item_on",
	"classeItem": ".plg_categoria_arvore_item",
	"classeSubOn": ".plg_categoria_arvore_sub_on",
	"classeSubs": ".plg_categoria_arvore_subs",
	"classeNav": ".plg_categoria_arvore_nav",
	"classeNavObj": ".plg_categoria_arvore_nav_obj",
	"classePai": ".plg_categoria_arvore_pai",

	"configurar": function(valor)
	{
		var me = this;

		if (valor != this.opSemArvore)
			$(this.classeItem).show();

		if (valor == this.opArvoreAberta)
		{
			$(this.classeItem).each(function(){
				$(this).find(me.classeSub).show();
				if ($(this).find(me.classeSub).length > 0)
					$(this).find(me.classeSubs).show();
			});
		}
		else if (!isNaN(valor))
		{
			var sValor = "" + valor;
			$(this.classeItem).each(function(){
				$(this).find(me.classeSub + ":lt(" + sValor + ")").show();
				if ($(this).find(me.classeSub).length > valor)
					$(this).find(me.classeMais).show();
				if ($(this).find(me.classeSub).length > 0)
					$(this).find(me.classeSubs).show();
			});
		};

				
		$(this.classeItemOn).find(this.classeSub).show();
		$(this.classeItemOn).find(this.classeMais).hide();
		if ($(this.classeItemOn).find(this.classeSub).length > 0)
				$(this.classeItemOn).find(this.classeSubs).show();
		$(this.classeItemOn).show();

		$(this.classeMais).click(function(){
			$(this).hide();
			$(this).parents(plg_categoria_arvore.classeItem +  ":first").find(plg_categoria_arvore.classeSub).slideDown("fast");
		});

	},

	"carregar": function(cod, pai, formato_n0, formato_n1, formato_n2)
	{
		$(this.classeNav).hide();
		$(this.classeItem).hide();
		$(this.classeSub).hide();
		$(this.classeSubs).hide();
		
		if (pai == "") pai = "XXX";
		if (cod == "") cod = "XXX";
		

		$(this.classeItem + pai).addClass(this.classeItemOn.replace(".", ""));
		$(this.classeItem + cod).addClass(this.classeItemOn.replace(".", ""));
		$(this.classeSub + cod).addClass(this.classeSubOn.replace(".", ""));

		if ($(this.classeItemOn).length == 0)
			this.configurar(formato_n0);
		else if ($(this.classePai).length > 0)
		{
			this.configurar(formato_n1);
			if (formato_n1 == this.opSemArvore)
				$(this.classeNav).show();

		}
		else
		{
			this.configurar(formato_n2);
			$(this.classeNav).show();
		}
		

		$(this.classeNavObj).change(function(){
			document.location.href = $(this).val();
		});

		
	}
};



