var t;
var $count, $ab = 0;


$(document).ready(function(){
	/* renomeia as li para o menu-footer e seu conteudo */
    $("#menu_footer li").each(function(index, element){	
		$(element)
			.attr("id", 'menu-footer-'+index)
			.attr('rel', 'content-footer-'+index); });
   
   $("#content-footer li").each(function(index, element){ $(element).attr("id", 'content-footer-'+index); });

	var mainMenuFooter, currentMenuFooter, currentContentFooter = '0', painel;

	$('#menu_footer li').click(function(){
		if ((!$('#'+currentContentFooter).is(':animated')) || ($ab == 0)) {
			var $this = $(this);
			$ab = $ab + 1; 
      
			mainMenuFooter = $this.attr('id');
			painel = $this.attr('rel');
			
			if ((mainMenuFooter != currentMenuFooter) && ( mainMenuFooter != 'menu-footer-2')){
				if ($('#footer_conteudo_top').hasClass('hidden')) {
					
					$('#apaga-restos').stop().fadeIn(1000);
					$('#footer_conteudo_top')
						.removeClass('hidden')
						.addClass('show')
						.animate({top:-8},200, function(){
							$('#footer_corpo_conteudo')
								.animate({opacity:1, height:142} ,500, function(){
									clearTimeout(t);
									t = $('#'+painel)
										.stop()
										.fadeIn(300, function(){
											$ab = $ab - 1; 
										});
								});
						});
				   
				   $('html, body').animate({
					   scrollTop: $('#bottom').offset().top
				   }, 700);
					$("#menu_footer li").each(function(index, element){	
						$(element)
							.removeClass('ativo')
							.addClass('inativo');
					});
					$(this)
						.removeClass('inativo')
						.addClass('ativo');
				}
				else {
					$(this)
						.removeClass('inativo')
						.addClass('ativo');
					$('#'+currentMenuFooter)
						.removeClass('ativo')
						.addClass('inativo');
	
					clearTimeout(t);
					t = $('#'+currentContentFooter)
						.stop()
						.fadeOut(300, function(){
							clearTimeout(t);
							t = $('#'+painel)
								.stop()
								.fadeIn(300);					
						});
				}
				currentContentFooter = painel;	
				currentMenuFooter = mainMenuFooter;
			}
			else
			{
				$('#footer_corpo_conteudo')
					.animate({opacity:1, height:0} ,500, function(){
						$('#apaga-restos').stop().fadeOut(50);
						$('#footer_conteudo_top')
							.animate({top:0},300,function(){
								$('#footer_conteudo_top')
									.removeClass('show')
									.addClass('hidden');
									$ab = $ab - 1; 
							});
					});
			   
			   $('html, body').animate({
				   scrollTop: $('#bottom').offset().top
			   }, 700, function(){
					$("#menu_footer li").each(function(index, element){	
						$(element)
							.removeClass('inativo')
							.removeClass('ativo');
					});
			   });

				$("#content-footer li").each(function(index, element){	
					$(element)
						.css('display','none');
				});
				$("#content-footer li").each(function(index, element){	
					clearTimeout(t);
					$(element)
						.stop()
						.fadeOut(300);
				});
				
				currentContentFooter = '0';	
				currentMenuFooter = '0';
			}
		}
	});
	$('.box-close').click(function(){

		$ab = $ab + 1; 
		$('#footer_corpo_conteudo')
			.animate({opacity:1, height:0} ,500, function(){
				$('#apaga-restos').stop().fadeOut(50);
				$('#footer_conteudo_top')
					.animate({top:0},300,function(){
						$('#footer_conteudo_top')
							.removeClass('show')
							.addClass('hidden');
							$ab = $ab - 1; 
					});
			});
	   
	   $('html, body').animate({scrollTop: $('#bottom').offset().top}, 700, function(){
				$("#menu_footer li").each(function(index, element){	
					$(element)
						.removeClass('inativo')
						.removeClass('ativo');
				});
		});

		$("#content-footer li").each(function(index, element){	
			$(element)
				.css('display','none');
		});
		$("#content-footer li").each(function(index, element){	
			clearTimeout(t);
			$(element)
				.stop()
				.fadeOut(300, function(){
				});
		});
		
		currentContentFooter = '0';	
		currentMenuFooter = '0';
	});
});


//animacao da seta do menu
var over = 0;
var opacidade;
$(window).load(function(){
	$("#marcador-menu").css({display: 'block', opacity: 0});
	$("ul#menu li").hover(function(){
		//console.log(this);
		var posicao = $(this).position();
		$(this).children('.separador').clearQueue().animate({width:30}, 200);
		$("#marcador-menu").clearQueue().animate({left: (posicao.left+22), top: (posicao.top+85), opacity: 1}, 200);
			over = 1;
		}, function(){
			over = 0;
			clearTimeout(opacidade);
			opacidade = setTimeout('animarOpacidade()', 100);
			if (!$('#marcador-menu').is(':animated'))
			{
				$(this).children('.separador').animate({width:0}, 200);
			}
			else
			{
				$(this).children('.separador').animate({width:0}, 200)
			}
		});
});
function animarOpacidade(){
	if(over == 0){
		$("#marcador-menu").animate({opacity: 0}, 100);
	}
	else {
		clearTimeout(opacidade);
	}
} 	
