/**  
 * 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		Fl�vio Johann
 * @copyright   Copyright (c) 2005-2008 Vis�oI Sistemas. (http://www.visaoi.com)
 * 
 */
 


function disableSelection(target){
if (typeof target.onselectstart!="undefined") //IE route
target.onselectstart=function(){return false}
else if (typeof target.style.MozUserSelect!="undefined") //Firefox route
target.style.MozUserSelect="none"
else //All other route (ie: Opera)
target.onmousedown=function(){return false}
target.style.cursor = "default"
}


function validateKey (evt)
{
	alert(evt.keyCode);
	if (evt.keyCode == '17'){
		alert("Comando Desativado");
		return false;
	}
	return true;
}

function carregar_caderno(offset) {
	$.get(baseurl+'/site/caderno/chamada/offset/'+offset, function(data){
	 	$('#chamada_impresso').html(data);
	});
}


function fecharBanner() {
	document.getElementById('banner_propaganda').style.display = 'none';
}

function playStream() {
		window.open(baseurl+'/site/home/player',"Player","height=280,width=390,left=150,top=150,scrollbars=auto");									
}

/*
 * fun��o que atualiza os bairros de acordo com a cidade escolhida
 * para o campo de busca
 */
$(function () {

	$('#topo').media({ 
	    width: 950,
    	height: 135,
	    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
	});
	
	$('#visaoi').media({ 
	    width: 70,
    	height: 40,
	    autoplay:  true,
	    src: baseurl+'/flash/site/visaoi.swf',
	    attrs:     { wmode:  'transparent' },  // object/embed attrs 
	    params:    { wmode:  'transparent' }, // object params/embed attrs 
	    caption:   false // supress caption text 
	});
	
	$('#propaganda').media({ 
	    width: 750,
    	height: 220,
	    autoplay:  true,
	    src: baseurl+'/flash/site/propaganda.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: "Informativo_VT",
    		numTweets: 2,
    		loaderText: "carregando...",
    		slideIn: true,
    		showHeading: true,
    		headingText: "Últimos Tweets",
    		showProfileLink: true
    	});
    }
	
	if($('#twittertv')[0]) {
    	$("#twittertv").getTwitter({
    		userName: "tvinformativo",
    		numTweets: 2,
    		loaderText: "carregando...",
    		slideIn: true,
    		showHeading: true,
    		headingText: "Últimos Tweets",
    		showProfileLink: true
    	});
    }
	
	
	carregar_caderno(0);
	
});


//Para abrir submenus verticais em menu horizontal

$(document).ready(function(){
	
	
	function dump(obj) {
		var out = '';
		for (var i in obj) {
			alert(i);
		}

		//alert(out);
	}
	
	disableSelection(document.body);
		
	//Menu Colapsado
	
	$('.dinamico').mouseover(function(){$(this).find('ul').show();});
	
	$('.dinamico').mouseout(function(){$(this).find('ul').hide();});

	
	
	
/*
	$('UL[id^=menu_] ul').hide();

	
	$('UL[id^=menu_] li').click(
	
			
				
	  function() {
		  $(this).find('a').next().slideToggle('normal');		  
	  });*/
			
	
	
	/*
	$('UL[id^=menu_] li').mouseover(
		function() {
			$(this).find('a').next().css('display','block');		  
		});
					
	$('UL[id^=menu_] li').mouseout(
		
		function() {
			$(this).find('a').next().css('display','none');		  
	});*/
	
	
	
	 $("ul.sf-menu").superfish({ 
	        animation: {height:'show'},   // slide-down effect without fade-in 
	        delay:     400               // 1.2 second delay on mouseout 
	 	  });
	 
	 
	 $('.tooltip4').tooltip({fontsize:'12px',fontcolor :'#5F5F5F'});
	 

	   
});



//Mostra o Campo CPF caso seja pessoa F�sica ou CNPJ caso seja Pessoa Jur�dica
function mostraTipoPessoa(){	
	//Abre a div dos anexos dos editais 
	$("#form_orcamento").each(
			function() {
				var tipo = $(this).find('#tipo').val();	
				//Se foi selecionado um tipo mostro somente o campo daquele tipo
				if(tipo){
					switch(tipo){
						case 'pf':
							$(this).find('#cpf, label[for="cpf"]').show();
							$(this).find('#cnpj, label[for="cnpj"]').hide();
							break;
							
						case 'pj':
							$(this).find('#cnpj, label[for="cnpj"]').show();
							$(this).find('#cpf, label[for="cpf"]').hide();
							break;		
					}
				}else{
					//sen�o escondo as op��es
					$(this).find('#cpf, label[for="cpf"]').hide();
					$(this).find('#cnpj, label[for="cnpj"]').hide();		
				}			  
			}			
	);	
}


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)");
	$(".linkPaginacao").each(
			function(){
				$(this).css('background-color','rgb(0,0,0)');
			}
	);
	$("#paginacao_"+posicao_atual).css('background-color','rgb(100,100,100)');
		
	//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;
	  if(tamanho > 1) 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 pesquisa_noticia() {
	var editoria = $("#editoria").val();
	var texto = $("#texto_noticia").val();
	
	$.post(
			baseurl+"/site/noticia/pesquisar/",
			{
				editoria: editoria, 
				texto: texto
			}
	);
	
}



