var areaAtual = location.href.split("/")[4];
	
$(function()
{
	//$(document.body).css("background-image", "url('/images/bg/" + areaAtual + ".jpg')");
	if($("#conteudo").height() < 270 && jQuery.browser.msie)
		$("#conteudo").css("height", "270px");
	
	//gera a lateral
	GerarLateral();
	
	//atribui os over no topo e na lateral
	$("#menuTopo li, #menuLateral li li").hover(
		function()
		{
			if(!this.img)
				this.img = $(this).find("img:first[alt!='']");
			
			if(this.img.length > 0)
			{
				if(!this.caminho)
				{
					this.caminho = this.img.attr("src");
					this.caminho = this.caminho.substr(0, this.caminho.lastIndexOf("."));
				}
				
				if(this.img.attr("src").indexOf("_over") == -1)
					this.img.attr("src", this.caminho + "_over.gif");
			}
			
			//limpa o intervalo de ocultar o menu
			clearTimeout(this.intervalo);
			//altera a class do link
			$(this).find("a:first").addClass("itemHover");
			//exibe a div
			$(this).find("div:first").fadeIn("fast");
		},
		function()
		{
			var item = $(this);
			//retira a class do link
			item.find("a:first").removeClass("itemHover");
			
			//oculta o menu após um intervalo
			this.intervalo = setTimeout(
				function()
				{
					item.find("div:first").fadeOut("fast");
				}
				, 500
			);
			
			if(this.img.length > 0)
			{
				if(this.img.attr("src").indexOf("_over") > -1)
					this.img.attr("src", this.caminho + ".gif");
			}
		}
	)
	
	
	$("#menuTopo li:has(ul)").find("a:first").addClass("itemComSubnivel");
	
	$("#menuTopo div").find("li:first[class!='itemComSubnivel']").css("backgroundImage", "none");
	
});

function GerarLateral()
{
	if(areaAtual.toLowerCase() == 'terapia')
		areaAtual = location.href.split("/")[5];
	
	if(areaAtual == "")
		return;
	
	var codigo = $("#" + areaAtual + " ul").html();
	
	if(codigo == null)
	{
		$("#menuLateral").hide();
		return;
	}
	
	$("#menuLateral").html("<ul>" + codigo + "</ul>");
	
	//remove as imagens do menu do topo
	$("#menuLateral img").remove();
	
	//insere as imagens do menu lateral
	var d = $("#menuLateral div div");
	d.prepend('<img src="/images/sub_menu_topo.gif" alt="" class="floatLeft" />');
	d.append('<img src="/images/sub_menu_base.gif" alt="" class="floatLeft" />');
	
	//altera a class dos itens que term subníveis
	$("#menuLateral li li:has(ul)").find("a:first").addClass("itemComSubnivel");
	
	//marca a lateral
	$("#menuLateral a[href$='" + location.pathname + "']:last").addClass("itemLateralMarcado");
	
	$(".imagemBoxLateral, .baseBoxLateral").show();
}
