// Lembrar de sempre especificar o que cada comando vai fazer
// e sempre usar da identeção pra pemitir uma melhor leitura
// do futuro desenvolvedor

$(document).ready(function() {
	$(".imagem-destaque").cycle({
		'before':  onBefore,
		'prev': ".prev",
		'next': ".next"
	});

	function onBefore(){
		$(".selecionada").each(function () {
	          $(this).removeClass("selecionada");
	    });

		$("#destaque_"+this.id).addClass("selecionada");
	}
	$(".lupa a").fancybox();
	$(".form .input label, .form .select label, .form .input-radio label, .form .bloco-area label ").wrap("<div class='bg-label-dir'><div class='bg-label-esq'></div></div>");
	$(".bg-label-dir").each(function(){
			x = $(this).children(".bg-label-esq").width();
			$(this).width(x+22);
	});
	
	$("#menu .ativo").each(function(){
		$(this).before('<div class="bg-ativo-menu"></div>');
		x = $(this).width();
		$(this).parent().children(".bg-ativo-menu").css({
		"width": x,
		 "background-color": "#578a13",
		"z-index": 2
		});
		if (jQuery.browser.msie) {
			DD_roundies.addRule('.bg-ativo-menu', "12 12 0 0");
		} else {
			$('.bg-ativo-menu').corners('top-right 12px, top-left 12px');
		}
		
	})
	
	$("#menu li > a").hover(
		function() {
			$(this).before('<div class="bg-ativo-menu"></div>');
			x = $(this).width();
			$(this).parent().children(".bg-ativo-menu").css({"width": x});
			
			if (jQuery.browser.msie) {
				DD_roundies.addRule('.bg-ativo-menu', "12 12 0 0");
			} else {
				$('.bg-ativo-menu').corners('top-right 12px, top-left 12px');
			}
		},
		function() {
			a = $(this).parent().find("div.bg-ativo-menu").length;
			if(!$(this).hasClass("ativo")) {
				$(this).parent().find("div.bg-ativo-menu").remove();
				$(this).parent().find("ignore").remove();
			}
		}
	);
});
