$(document).ready(function() {

	/* Tabs generica */ 

	$(".tab_content").hide();
	$("ul.tabs li:first-child").addClass("active").show();
	$(".tab_content:first-child").show();
	
	$("ul.tabs li").click(function() {
		var activeTab = $(this).find("a").attr("href"); 
		$(this).parent().find("li").removeClass("active");
		$(this).addClass("active");
		$(activeTab).parent().find(".tab_content").hide(); 
		$(activeTab).fadeIn(); 
		return false;
	});

	/* Slideshow generico */ 
	var bolotas = new Array();
	var bolotasInv = new Array();
	var i=0;
	var bolaAtual=0;
	var bolaAtualId='';
	
	$('div.bolas img').each(function(index) {
		//alert(index);
		bolotas[i] = $(this).attr('id');
		bolotasInv[($(this).attr('id'))] = i;
		i++;
	  });
	  
	$(".slide_noticia").hide();
	$("div.bolas img:first").attr('src','imagens/bola-on.png'); //bolinha
	$(".slide_noticia:first-child").show();
	
	var t=setTimeout(vaiTempo,1000);	
	var tx=0;
	function vaiTempo(){
		tx++;
		//console.log(tx);
		if(tx>5){
			tx=0;
			mudaBola(bolaAtual+1);
		} else {
			t=setTimeout(vaiTempo,1000);
		}
	}
	
	
	function mudaBola(qual){
		clearTimeout(t);
		if(qual>bolotas.length-1){
			qual=0;
		}
		var activeTab = bolotas[qual];
		bolaAtualId=activeTab;
		bolaAtual=bolotasInv[bolaAtualId];
		
		$('#'+bolaAtualId).parent().parent().find("img").attr('src','imagens/bola-off.png'); //bolinha
		$('#'+bolaAtualId).attr('src','imagens/bola-on.png'); //bolinha
		
		$('#'+activeTab+'_cont').parent().find(".slide_noticia").fadeOut('slow'); 
		$('#'+activeTab+'_cont').fadeIn('slow', function() {
			t=setTimeout(vaiTempo,1000);
		});
 
		return false;
	}
	
	$("div.bolas img").click(function() {
		mudaBola(bolotasInv[$(this).attr("id")]);
	});
 
});

	function more_content(pagina,parametros,paginacao,loaded_messages,num_messages,morebt,morecont,funcaoPos){
			morebt = typeof(morebt) != 'undefined' ? morebt : '#more_button';
			morecont = typeof(morecont) != 'undefined' ? morecont : '#main_content';
			funcaoPos = typeof(funcaoPos) != 'undefined' ? funcaoPos : false;

			$(morebt).html('<img src="imagens/loader.gif" alt="" />');
			$.get(pagina + loaded_messages + parametros, function(data){
				$(morecont).append(data);
				$(morebt).html('<strong>mais</strong> <img src="imagens/seta-cinza-g.png" width="6" height="9" alt="" />');
				if(funcaoPos){
					funcaoPos();
				}
			});
	
			if(loaded_messages >= num_messages - paginacao)
			{
				$(morebt).hide();
			}else{
				$(morebt).show();
			}
				
			
			return loaded_messages += paginacao;
	}
	
	function carrega(pagina,target){
		$("#"+target).html('<img src="imagens/loader.gif" alt="Carregando" title="Carregando" />');
		$.get(pagina, function(data){
			$("#"+target).html(data);
		});
	}


