/**  
 * VisãoI Sistemas
 * visaoi@visaoi.com.br
 * 
 * Rua Marcílio Dias, 26
 * Bairro Americano - Lajeado - RS
 * (51)3011-7001 | (51)8424-4494
 * 
 * DESCRIÇÃO
 * Javascripts do módulo site
 *
 * @author		Francisco Schwertner
 * @copyright   Copyright (c) 2005-2008 VisãoI Sistemas. (http://www.visaoi.com)
 * 
 */
 
 

/*
 * função que atualiza os bairros de acordo com a cidade escolhida
 * para o campo de busca
 */
 
$(function () {

	$('#topo').media({ 
	    width: 980,
    	height: 145,
	    autoplay:  true,
	    bgColor: '', 
	    src: baseurl+'/flash/site/topo.swf',
	    attrs:     { wmode:  'transparent' }, // object/embed attrs 
	    params:    { wmode:  'transparent' }, // object params/embed attrs 
	    caption:   false // supress caption text
	});
	
	$('#logoVisaoi').media({ 
	    width: 68,
    	height: 38,
	    autoplay:  true,
	    src: baseurl+'/flash/site/logoVisaoi.swf',
	    attrs:     { wmode:  'transparent' },  // object/embed attrs 
	    params:    { wmode:  'transparent' }, // object params/embed attrs 
	    caption:   false // supress caption text 
	});
	
	$('#bannerKbs').media({ 
	    width: 400,
    	height: 85,
	    autoplay:  true,
	    src: baseurl+'/flash/site/bannerKbs.swf',
	    attrs:     { wmode:  'transparent' },  // object/embed attrs 
	    params:    { wmode:  'transparent' }, // object params/embed attrs 
	    caption:   false // supress caption text 
	});

	
	if($('#twitter')[0]) {
    	$("#twitter").getTwitter({
    		userName: "valedoesporte",
    		numTweets: 2,
    		loaderText: "Carregando mensagens ...",
    		slideIn: true,
    		showHeading: true,
    		headingText: "",
    		showProfileLink: true
    	});
    }
	

});

//Para abrir submenus verticais em menu horizontal	
$(function(){
	
	//Modificado o plugin JDMENU na linha 116 #Comentário //debug
	//Para evitar que o menu sumisse ao clicar em um link
	$('#jd_menu').each(function() {
		$(this).jdMenu();
	});
   
   $("div#resultado").hide();	
   
});


//Inicia o SlideShow
function slideShow(posicao_atual,tempo,tamanho){
	
	var time;		
	//Esconde as outras divs e mostra somente a atual;
	limparDivs(tamanho);
	$("div#content_"+posicao_atual).show();
	$("#controle_"+posicao_atual).removeClass('tdLaranja').addClass('tdVerde');
	//("background-color","rgb(255,255,255)");
	
	$(".tdLaranja").each(
			function(){
				$(this).css('background-color','rgb(252, 136, 1)');
			}
	);
	$("#controle_"+posicao_atual).css('background-color','rgb(161, 190, 20)');

	
	
		
	//Se não for passado tempo, vai trocando a noticia a cada 4 segundos
	if(tempo == null || tempo == undefined){
		time = 4000;
	}else{
	//senão demora o tempo estipulado para trocar de notícia
		time = tempo;
	}
	//Enquanto não chegar na ultima noticia vai trocando as noticias 
	//em ordem
	if((posicao_atual+1) < tamanho){
	  posicao_atual = posicao_atual+1;
	  timer = setTimeout("slideShow("+posicao_atual+","+tempo+","+tamanho+")",time);
	}else{
	  //caso chegar na ultima, iniciar a contagem da primeira posição.		
	  posicao_atual = 0;
	  clearTimeout(timer);
	  timer = setTimeout("slideShow("+posicao_atual+","+tempo+","+tamanho+")",time);
	}
}




//Função para limpar as divs
function limparDivs(tamanho){
	var c;	
	$("[@id^=content_]").hide();
	$("[@id^=controle_]").removeClass('tdVerde').addClass('tdLaranja');
	
	
}



//Chamada ao clicar no controle da noticia
//Diminui o tempo de transição do slideshow
//mostra a notícia selecionada
function mudaNoticia(pos,t,tamanho){
	tempo = t;
	clearTimeout(timer);
	slideShow(pos,t,tamanho);
}


function centralizaDivAviso(){
	var larguraTela = screen.width;
	var alturaTela = screen.height;	
	var divAviso = $("#divAviso");
	var botaoFechar = $("#botaoFechar");
	var larguraDiv = divAviso.width();
	var alturaDiv  = divAviso.height();	
	var marginTop = parseInt(alturaDiv/2);
	var marginLeft = parseInt(larguraDiv/2);
	var popup_top = alturaTela / 2 - alturaDiv / 2;
    var popup_left = larguraTela / 2 - larguraDiv / 2;

    $("#divAviso").css({'margin':'-'+marginTop+'px -'+marginLeft+'px'});    
   
   	var topAviso = ($(divAviso).offset().top)-(botaoFechar.height());
	var leftAviso = ($(divAviso).offset().left) + (larguraDiv-botaoFechar.width());    
    	
    $("#botaoFechar").css({
    	'top' :  topAviso + 'px',
        'left' : leftAviso + 'px',
        'cursor':'pointer'
   });
    
}


//contador, a faz sumir o banner apos certo tempo
function contaTempoAviso(contador) {	
	if(contador == 0) {
		$("#botaoFechar").trigger('click');
		//alert("fechou");
	}	
	if (contador != 0){
		contador = contador-1;
		setTimeout("contaTempoAviso("+contador+")", 1000);
	}
}

function expandirBanner(id,width){
	document.getElementById('banner_'+id).style.clip = 'rect(0px,'+width+'px,300px,0px)';
}
function encolherBanner(id,width){
	document.getElementById('banner_'+id).style.clip = 'rect(0px,'+width+'px,95px,0px)';
}





