jQuery.fn.exists = function(){return jQuery(this).length>0;}

$(document).ready(
	function()
	{
		var url = "";
		$("#topo ul li a").each(
			function()
			{				
				if (document.location.href.indexOf($(this).attr("href")) > 0)
				{
					$($(this).parent()).addClass("fundo-sel");
				}				
			}	
		);		
		setInterval(
			function()
			{				
				if(url != document.location && location.pathname.indexOf("Cases.aspx") > 0)
				{										
					vhref = new String(document.location);
					vhref = vhref.split("#");											
					if($("#"+vhref[1]).exists())
					{					
						$("#divTodos > div").hide();
						$("#"+vhref[1]).show();	
						url = document.location;
					}
					
				}
			},1000

		);

		$("#quando_ha_crise a").click(
			function()
			{	
				vhref = this.href.split("#")[1];				

				if ($(vhref).val() != '')
				{					
					if ($("#"+vhref).css("display") == "block")
					{
						$("#"+vhref).hide();					
					}
					else
					{
						$("#quando_ha_crise div").hide();
						$("#"+vhref).show('slow');
					}	
					return false;
				}
			}
		);

		$("#menu_empresa td a").click(
			function()
			{
				$("#menu_empresa td a").each(
					function()
					{						
						$(this).css("font-weight","normal");					
					}
				);
				$(this).css("font-weight","bold");
				vhref = this.href.split("#")[1];				
				$("#divTodos div").hide();
				$("#"+vhref).show();
				return false;
			}
		);

		$("#menu_atuacao td a").click(
			function()
			{
				$("#menu_atuacao td a").each(
					function()
					{						
						$(this).css("font-weight","normal");			
					}
				);
				$(this).css("font-weight","bold");
				vhref = this.href.split("#")[1];
				$("#divTodos > div").hide();
				$("#"+vhref).show();
				return false;
			}
		);

		if(location.href.indexOf("#") > 0)
	    {			
			vhref = location.href.split("#")[1];                                       
            $("#divTodos > div").hide();
            $("#"+vhref).show(); 
			$("#menu_empresa td a").each(
					function()
					{   
						if ($(this).attr("href") == "#"+vhref)
						{
						    $(this).css("font-weight","bold");
						}
					}
				);	
			$("#menu_atuacao td a").each(
					function()
					{   
						if ($(this).attr("href") == "#"+vhref)
						{
						    $(this).css("font-weight","bold");
						}
					}
				);		
        }
		else
		{
            $("#divTodos div:first").show();
			$("#menu_atuacao td a:first").css("font-weight","bold");            
        }

		if(location.pathname.indexOf("Fale_Conosco.aspx") > 0)
		{
			$("input[name*='Telefone']").mask("99-99999999");
		}

	}

);
