$(function (){
	$("#menuPrincipal li, #menuSecundario li").hover(function (){
		$(this).find("ul").css("left","183px");
	}, function (){
		$(this).find("ul").css("left","-9999px");
	});

	$("#tableSexagem thead tr th:first, #tableIMC thead tr th:first").css("background","url(../../img/exames/bgr_thead.jpg) top left no-repeat");
	$("#tableSexagem thead tr th:last, #tableIMC thead tr th:last").css("background","url(../../img/exames/bgr_thead.jpg) top right no-repeat");
	$("#tableSexagem thead tr th, #tableIMC thead tr th").css("background-color","#A5C7A0");

	$("#tableSexagem tbody tr:even").each(function (){
		$(this).find("td").each(function (i){
			if (i == 0){
				$(this).css("background","url(../../img/exames/bgr_tbody.jpg) top left no-repeat");
			} else if (i == 3){
				$(this).css("background","url(../../img/exames/bgr_tbody.jpg) top right no-repeat");
			}
		});
	});

	$("#tableIMC tbody tr:even").each(function (){
		$(this).find("td").each(function (i){
			if (i == 0){
				$(this).css("background","url(../../img/exames/bgr_tbody.jpg) top left no-repeat");
			} else if (i == 1){
				$(this).css("background","url(../../img/exames/bgr_tbody.jpg) top right no-repeat");
			}
		});
	});

	$("#tableSexagem tbody tr:even td, #tableIMC tbody tr:even td").css("background-color","#FBFCFA");

	$("#tableSexagem tbody tr:odd").each(function (){
		$(this).find("td").each(function (i){
			if (i == 0){
				$(this).css("background","url(../../img/exames/bgr_tbody_odd.jpg) top left no-repeat");
			} else if (i == 3){
				$(this).css("background","url(../../img/exames/bgr_tbody_odd.jpg) top right no-repeat");
			}
		});
	});

	$("#tableIMC tbody tr:odd").each(function (){
		$(this).find("td").each(function (i){
			if (i == 0){
				$(this).css("background","url(../../img/exames/bgr_tbody_odd.jpg) top left no-repeat");
			} else if (i == 1){
				$(this).css("background","url(../../img/exames/bgr_tbody_odd.jpg) top right no-repeat");
			}
		});
	});

	$("#tableSexagem tbody tr:odd td").css("background-color","#CCDFC9");

	$(".listaPerguntas dt a").hover(function (){
		$(this).parent("dt").addClass("on");
		$(this).parent("dt").css("backgroundPosition","0 -63px");
	}, function (){
		$(this).parent("dt").removeClass("on");
		$(this).parent("dt").css("backgroundPosition","0 0px");
	}).click(function (){
		if ($(this).parent("dt").next().css("display") == "none"){
			$(".listaPerguntas dd").hide();
			$(this).parent("dt").next().slideDown();
			$(this).parent("dt").css("background","transparent url(../../img/geral/btn_menos.gif) top left no-repeat");
		} else {
			$(this).parent("dt").next().slideUp();
			$(this).parent("dt").css("background","transparent url(../../img/geral/btn_mais.gif) top left no-repeat");
		}
	});
	
	$(".modal").facebox();

	$("#btnCalcular").hover(function (){
		$(this).css("background-position","0 -20px");
	}, function (){
		$(this).css("background-position","0 0");
	});

	$("#listaImg a img").hover(function (){
		$(this).attr("src","../../img/geral/moldura_on.gif");
	}, function (){
		$(this).attr("src","../../img/geral/moldura.gif");
	});

	img = new Image;
	img.src = "../../img/geral/moldura_on.gif";

	$(".selHome a").click(function (){
		if ($(this).parents(".selHome").find("ul").css("display") == "none") {
			$(this).parents(".selHome").find("ul").slideDown();
			$(this).parents(".selHome").find("a").css("background-position","0 -20px");
		} else {
			$(this).parents(".selHome").find("ul").slideUp("normal", function () {
				$(this).parents(".selHome").find("a").css("background-position","0 0");
			});
		}
	});

	$(".selHome li:not(:last)").hover(function (){
		$(this).addClass("on");
	}, function (){
		$(this).removeClass("on");
	}).click(function (){
		$(this).parents(".selHome").find("ul").slideUp("normal", function () {
			$(this).parents(".selHome").find("a").css("background-position","0 0");
		});
	});

	$(".selHome li:last").hover(function (){
		$(this).addClass("ultimoOn");
	}, function (){
		$(this).removeClass("ultimoOn");
	}).click(function (){
		$(this).parents("ul").slideUp();
	});

	$(".selFale a").click(function (){
		if ($(this).parents(".selFale").find("ul").css("display") == "none") {
			$(this).parents(".selFale").find("ul").slideDown();
		} else {
			$(this).parents(".selFale").find("ul").slideUp();
		}
	});

	$(".selFale li:not(:last)").hover(function (){
		if ($(this).attr("class") != "primeiro" && $(this).attr("class") != "ultimo") {
			$(this).addClass("on");
		}
	}, function (){
		if ($(this).attr("class") != "primeiro") {
			$(this).removeClass("on");
		}
	}).click(function (){
		$(this).parents(".selFale").find("ul").slideUp();
		$(this).parents(".selFale").find("a").text($(this).text());
	});

	$(".selFale li.ultimo").hover(function (){
		$(this).addClass("ultimoOn");
	}, function (){
		$(this).removeClass("ultimoOn");
	}).click(function (){
		$(this).parents("ul").slideUp();
		$(this).parents(".selFale").find("a").text($(this).text());
	});

	$(".selFale li.primeiro").hover(function (){
		$(this).addClass("primeiroOn");
	}, function (){
		$(this).removeClass("primeiroOn");
	}).click(function (){
		$(this).parents("ul").slideUp();
		$(this).parents(".selFale").find("a").text($(this).text());
	});

	$(".selCustom li").click(function (){
		var index = $(".selCustom li").index($(this));
		var $this = $(this);
		var id = $(this).parents(".selCustom").attr("id");
		id = id.replace("Fake","");
		$("#" + id + " option").eq(index).attr("selected","selected");
	});

	$(".date").mask("99/99/9999");

	$(".btnVoltar").click(function (){
		window.history.back();
	});
});
