/* Cufon */
Cufon.replace('.cufon');

$().ready(function(){
	/* Formulários */
	$(".validar").validate();
	
	/* Máscaras */
	$(".telefone").mask("(99) 9999-9999");
   	$(".cep").mask("99999-999");
   	$(".cnpj").mask("99.999.999/9999-99");
   	$(".cpf").mask("999.999.999-99");
   	$(".data").mask("99/99/9999");
	$(".hora").mask("99:99");
	
	/* Datepicker JQuery UI*/
	$('.datepicker').datepicker({
		inline: true,
		dateFormat: "dd/mm/yy",
		dayNamesMin: ['Dom', 'Seg', 'Ter', 'Qua', 'Qui', 'Sex', 'Sab'],
		monthNames: ['Janeiro','Fevereiro','Mar&ccedil;o','Abril','Maio','Junho','Julho','Agosto','Setembro','Outubro','Novembro','Dezembro']
	});
});

/* Sliders */
$(document).ready(function(){    
    $("#tv_slider").cycle({ 
        pager:  '#tv_pager',
        before: onBefore,
    	after: onAfter,
        timeout: 10000 
    });
});

function onBefore() {
    $('.tv_item_descricao').hide();
}

function onAfter() {
    $('.tv_item_descricao').css({opacity: '1'}).fadeIn();
}


/* Tweets */
$(document).ready(function(){
    $(".destaque_tweets").tweet({
        username: "viapar",
        count: 1,
        template: "{text}{join}",
        loading_text: "Carregando"
    });
});


/* Tweets2 */
$(document).ready(function(){
    $(".destaque_tweets2").tweet({
        username: "viapar",
        count: 5,
        template: "{text}{join}",
        loading_text: "Carregando"
    });
});


/* Tabs */
$(document).ready(function(){   
    $("#rodovias_menu ul").idTabs(); 
});

/* Busca Noticias */
$(document).ready(function(){ 
	$('#form_busca #busca').focus(function(){
		if($(this).val() == "Digite a busca"){
			$(this).val("");
		}
	});
		
	$('#form_busca #busca').blur(function(){
		if($(this).val() == ""){
			$(this).val("Digite a busca");
		}
	});
});

/* Processos C.A.U. */
$(document).ready(function(){ 
	
	$('#form_processos #cpf').val('CPF');
	$('#form_processos #cpf').focus(function(){
		if($(this).val() == "CPF"){
			$(this).val("");
		}
	});
	$('#form_processos #cpf').blur(function(){
		if($(this).val() == ""){
			$(this).val("CPF");
		}
	});
	
	$('#form_processos #processo').val('Nº do Processo');
	$('#form_processos #processo').focus(function(){
		if($(this).val() == "Nº do Processo"){
			$(this).val("");
		}
	});
	$('#form_processos #processo').blur(function(){
		if($(this).val() == ""){
			$(this).val("Nº do Processo");
		}
	});
	
});

/* Formulario Contato */
$(document).ready(function(){
	
	//Esconde todos os campos ao carregar
	$('#dinamico p').slideUp(0);
	
	//Carrega campos via Ajax JSON
	$('#contato #tipo').change(function(){
		$('#dinamico p').slideUp('fast');
		$.ajax({
			type: "POST",
			dataType: "json",
			url: "_ajax_formularios.php",
			data: ({id : $('#contato #tipo').val()}),
			beforeSend: function(){
				$('#contato #assunto option').remove();
				$('#contato #assunto').append('<option value="">Selecione</option>');
			},
			success: function(json){
				
				for(var i in json){
					$('#contato #assunto').append('<option value="'+json[i].id+'">'+json[i].nome+'</option>');
				}
				
				$('#contato #tipo').find('option.selecione').remove();
				$('#contato #assunto').removeAttr('disabled');
				$('#contato #assunto').focus();
			}
		});
	});
	
	$('#contato #assunto').change(function(){
		$.ajax({
			type: "POST",
			dataType: "json",
			url: "_ajax_campos.php",
			data: ({id : $('#contato #assunto').val()}),
			beforeSend: function(){
				$('#dinamico input[type="text"]').removeClass('required');
				$('#dinamico p').slideUp('fast');
			},
			success: function(json){
				
				for(var i in json){
					$('#dinamico p').each(function(){
						if ($(this).find('input').attr('id') == json[i]){
							$(this).find('input[type="text"]').addClass('required');
							$(this).slideDown('fast');
						}
					});
				}
				
				$('#contato .campo').removeAttr('disabled');
			}
		});
	});
});

//COLUNAS MAXH
$(window).load(function() {
	var sizes = [];
	$('#destaques .destaque_item').each(function(){
		 sizes.push($(this).height()); 
	});
	var max = Math.max.apply(null, sizes);
	$('#destaques').height($('#destaques .destaque_item').height(max));
});

/* Scroll */
$(document).ready(function() {     
    $('.voltar_topo').click(function () {  
        $.scrollTo(this.hash, 1500, { easing:'easeInOutExpo'});
        return false;  
    });  
});


/* Galeria Zoom */
$(document).ready(function(){  
	$("a[rel=galeria_zoom]").fancybox({
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'titlePosition' 	: 'over',	
		'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
		    return '<span id="fancybox-title-over">Imagem ' +  (currentIndex + 1) + ' / ' + currentArray.length + ' ' + title + '</span>';
		}
	});
        
        /* fancybox iframe */
        $("#boxTexto").fancybox({
                'width'             : 800,
                'height'            : 500,
                'autoScale'         : false,
                'transitionIn'      : 'elastic',
                'transitionOut'     : 'elastic',
                'titlePosition'     : 'over',
                'type'              : 'iframe'
        }); 
        
        /* fancybox iframe  esqueci senha */
        $("#esqueciSenha").fancybox({
                'width'             : 350,
                'height'            : 200,
                'autoScale'         : false,
                'transitionIn'      : 'elastic',
                'transitionOut'     : 'elastic',
                'titlePosition'     : 'over',
                'type'              : 'iframe'
        });
       
});




