// JavaScript Document
$(document).ready(function(){

// ULTIMAS NOTICIAS ///////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
	if (typeof(timerNoticias) != 'undefined'){clearTimeout(timerNoticias);}
	if ($("#numNotices").val() > 1){
		tempo(0);
	}

	$("li.tb a").click(function(){
		//alert($(this).html());
		var j		= $("#numNotices").val();
		var titulo 	= $(this).html();
		var foto	= $(this).attr("href");
		var id		= $(this).attr("id");
		var n 		= id.replace("a","");
		var idNotice	= $(this).attr("rel");
		idNotice		= idNotice.replace("id","");
		stoper();
		
		for (i=0;i<j;i++){$("#a"+i).removeClass("selected");}
		$(this).addClass("selected");

		trocaImagem(foto,n,titulo,idNotice);
		
		//$("b#titulonoticia").html(titulo);
		//$(".fotoDestaque").css({ background:"url(adm/imgNoticias/Destaques/"+foto+")" });
		
		return false;
	});

// TABELA DE JOGOS ////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
	if (typeof(timerMsg) != 'undefined'){clearTimeout(timerMsg);}
	temporizaMsg(1);



// TWITTER /////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
	$("#twitter span.twitts").getTwitter({
		userName: "vivofrancabc",
		numTweets: 6,
		loaderText: "Loading tweets...",
		slideIn: true,
		slideDuration: 7,
		showHeading: true,
		headingText: "",
		showProfileLink: false,
		showTimestamp: true
	});


// NEWSLATTER /////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
	$('#nome').focus(function(){ //-> LIMPA CAMPO
		if ($(this).val()=="Digite seu Nome"){
			$(this).val("");  
		}
	});
	$('#nome').blur(function(){ //-> ESCREVE NO VAMPO CAMPO
		if($(this).val().length<4){ 
			$(this).val("Digite seu Nome"); 
		}
	}); 
	$('#email').focus(function(){ //-> LIMPA CAMPO
		if ($(this).val()=="Digite seu E-mail"){
			$(this).val("");  
		}
	});
	$('#email').blur(function(){ //-> ESCREVE NO VAMPO CAMPO
		if($(this).val().length<4){ 
			$(this).val("Digite seu E-mail"); 
		}
	}); 
	
	$('#AddNews').click(function(){
		var nome  		= $('#nome').val();
		var email 		= $('#email').val();
		var formAction 	= $('#fnewslatter').attr('action');
		//var aleatorio	= Math.ceil(Math.random() * 100000 );
		
		if(nome!="Digite seu Nome" && email!="Digite seu E-mail"){
			if ($('#fnewslatter')!=undefined) fPost('#fnewslatter','#rNewslatter')
		}else{
			return false;
		}
	});
	
// ENQUETE ////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
	if ($('#fEnquete')!=undefined) fPost('#fEnquete','#rEnquete')
	$('#fEnquete').submit(function(){
		$(this).fadeOut('fast',function(){
			$("#rEnquete").fadeIn('fast');
		});
	});
	

		$("a#resultados").click(function(){
			var idEnquete = $(this).attr("href");
			idEnquete = idEnquete.replace("#","");
			$(this).removeAttr("id");
			$(this).attr("id","formulario");
			$(this).html('Formul&aacute;rio de Vota&ccedil;&atilde;o');
			$("#rEnquete").html("");
	
			$("#fEnquete").css({display:"none"});
			$("#rEnquete").css({display:"block"});
			$("#rEnquete").load("?session=enquete&act=results&idEnquete="+idEnquete+"&ajax");	
			return false;							 
		});

	resultados();

	$("#rEnquete").ajaxComplete(function(){
		resultados();
	});



});

function resultados(){
	
		$("a#resultados").click(function(){
			var idEnquete = $(this).attr("href");
			idEnquete = idEnquete.replace("#","");
			$(this).removeAttr("id");
			$(this).attr("id","formulario");
			$(this).html('<strong>Formul&aacute;rio de Vota&ccedil;&atilde;o</strong>');
			$("#rEnquete").html("");
	
			$("#fEnquete").css({display:"none"});
			$("#rEnquete").css({display:"block"});
			return false;							 
		});


		$("a#formulario").click(function(){
			$(this).removeAttr("id");
			$(this).attr("id","resultados");
			$(this).html('Confira os <strong>Resultados</strong>');

			$("#rEnquete").html('');
			$("#rEnquete").css({display:"none"});
			$("#fEnquete").css({display:"block"});
			return false;							 
		});
	
}
function altMsg(n){
	$("#mensagem"+n).fadeOut( 'fast',function(){
		if(n==2){n = 1;}else{n = n+1;}
		$("#mensagem"+n).fadeIn('fast');
	});
	temporizaMsg(n);
}
function temporizaMsg(n){
	timerMsg  = window.setTimeout("altMsg("+n+")",1000);
}


//FUNCOES PARA ULTIMAS NOTICIAS ////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
function tempo(n){
	timerNoticias  = window.setTimeout("incremento("+n+")",5000);
	//stoper();
}

function incremento(n){
	var imagem;
	var titulo;
	var idNotice;
	var nArquivos = $("#numNotices").val();
	if(!n){n=0;}

	$("#a"+n).removeClass("selected");
	
	n = n + 1;
	if(n>nArquivos-1){n=0;}
	
	
	imagem = $("#a"+n).attr("href");
	titulo = $("#a"+n).html();
	idNotice = $("#a"+n).attr("rel");
	idNotice = idNotice.replace("id","");

	$("#a"+n).addClass("selected");

	trocaImagem(imagem,n,titulo,idNotice);
}

function trocaImagem(imagem,n,titulo,idNotice) {
	stoper();
	/*
	$("a.fotoDestaque").css({ background: "url(adm/imgNoticias/Destaques/"+imagem+")" });
	$("#titulonoticia").html(titulo);
	$("a.fotoDestaque").attr("href","?session=noticias&id="+idNotice);
	$("a.fotoDestaque").fadeIn('fast');
	*/
	
	$("a.fotoDestaque").fadeOut('normal',function(){
		$("a.fotoDestaque").css({ background: "url(adm/imgNoticias/Destaques/"+imagem+")" });
		$("#titulonoticia").html(titulo);
		$("a.fotoDestaque").attr("href","?session=noticias&id="+idNotice);
		$("a.fotoDestaque").fadeIn('normal');
	});
	tempo(n);
}

function stoper() {
	clearTimeout(timerNoticias);
}