(function () {
  'use strict'

  document.querySelector('#navbarSideCollapse').addEventListener('click', function () {
    document.querySelector('.offcanvas-collapse').classList.toggle('open')
  })

  $(document).ready(function () {

    //aumentar fonte
    $("#aumentarFonte").click(function(){

      var tamanhoFonte = parseInt( $("h1").css( 'fontSize' ) );
      tamanhoFonte = ( tamanhoFonte+1 )+'px';
      $("h1").css({ fontSize: tamanhoFonte });

      var tamanhoFonte = parseInt( $("h2").css( 'fontSize' ) );
      tamanhoFonte = ( tamanhoFonte+1 )+'px';        
      $("h2").css({ fontSize: tamanhoFonte }); 

      var tamanhoFonte = parseInt( $("h3").css( 'fontSize' ) );
      tamanhoFonte = ( tamanhoFonte+1 )+'px';        
      $("h3").css({ fontSize: tamanhoFonte }); 

      var tamanhoFonte = parseInt( $("h4").css( 'fontSize' ) );
      tamanhoFonte = ( tamanhoFonte+1 )+'px';        
      $("h4").css({ fontSize: tamanhoFonte }); 

      var tamanhoFonte = parseInt( $("h5").css( 'fontSize' ) );
      tamanhoFonte = ( tamanhoFonte+1 )+'px';        
      $("h5").css({ fontSize: tamanhoFonte });                 

      var tamanhoFonte = parseInt( $("h6").css( 'fontSize' ) );
      tamanhoFonte = ( tamanhoFonte+1 )+'px';        
      $("h6").css({ fontSize: tamanhoFonte }); 

      var tamanhoFonte = parseInt( $("p").css( 'fontSize' ) );
      tamanhoFonte = ( tamanhoFonte+1 )+'px';                                                     
      $("p").css({ fontSize: tamanhoFonte });        

      var tamanhoFonte = parseInt( $("span").css( 'fontSize' ) );
      tamanhoFonte = ( tamanhoFonte+1 )+'px';                                                     
      $("span").css({ fontSize: tamanhoFonte }); 

      var tamanhoFonteTxt = parseInt( $(".fonte_acessibilidade").css( 'fontSize' ) );
      tamanhoFonteTxt = ( tamanhoFonteTxt+1 )+'px';                                                     
      $(".fonte_acessibilidade").css({ fontSize: tamanhoFonteTxt });         

  });
  //diminuit fonte
  $("#diminuirFonte").click(function(){

      var tamanhoFonte = parseInt( $("h1").css( 'fontSize' ) );
      tamanhoFonte = ( tamanhoFonte+1 )+'px';
      $("h1").css({ fontSize: tamanhoFonte });

      var tamanhoFonte = parseInt( $("h2").css( 'fontSize' ) );
      tamanhoFonte = ( tamanhoFonte-1 )+'px';        
      $("h2").css({ fontSize: tamanhoFonte }); 

      var tamanhoFonte = parseInt( $("h3").css( 'fontSize' ) );
      tamanhoFonte = ( tamanhoFonte-1 )+'px';        
      $("h3").css({ fontSize: tamanhoFonte }); 

      var tamanhoFonte = parseInt( $("h4").css( 'fontSize' ) );
      tamanhoFonte = ( tamanhoFonte-1 )+'px';        
      $("h4").css({ fontSize: tamanhoFonte }); 

      var tamanhoFonte = parseInt( $("h5").css( 'fontSize' ) );
      tamanhoFonte = ( tamanhoFonte-1 )+'px';        
      $("h5").css({ fontSize: tamanhoFonte });                 

      var tamanhoFonte = parseInt( $("h6").css( 'fontSize' ) );
      tamanhoFonte = ( tamanhoFonte-1 )+'px';        
      $("h6").css({ fontSize: tamanhoFonte }); 

      var tamanhoFonte = parseInt( $("p").css( 'fontSize' ) );
      tamanhoFonte = ( tamanhoFonte-1 )+'px';                                                     
      $("p").css({ fontSize: tamanhoFonte });        

      var tamanhoFonte = parseInt( $("span").css( 'fontSize' ) );
      tamanhoFonte = ( tamanhoFonte-1 )+'px';                                                     
      $("span").css({ fontSize: tamanhoFonte }); 

      var tamanhoFonteTxt = parseInt( $(".fonte_acessibilidade").css( 'fontSize' ) );
      tamanhoFonteTxt = ( tamanhoFonteTxt-1 )+'px';                                                     
      $(".fonte_acessibilidade").css({ fontSize: tamanhoFonteTxt });         

  });
  //aumentar fonte
  $("#aumentarFonteTxt").click(function(){

      var tamanhoFonteTxt = parseInt( $("h1").css( 'fontSize' ) );
      tamanhoFonteTxt = ( tamanhoFonteTxt+1 )+'px';
      $("h1").css({ fontSize: tamanhoFonteTxt });

      var tamanhoFonteTxt = parseInt( $("h2").css( 'fontSize' ) );
      tamanhoFonteTxt = ( tamanhoFonteTxt+1 )+'px';        
      $("h2").css({ fontSize: tamanhoFonteTxt }); 

      var tamanhoFonteTxt = parseInt( $("h3").css( 'fontSize' ) );
      tamanhoFonteTxt = ( tamanhoFonteTxt+1 )+'px';        
      $("h3").css({ fontSize: tamanhoFonteTxt }); 

      var tamanhoFonteTxt = parseInt( $("h4").css( 'fontSize' ) );
      tamanhoFonteTxt = ( tamanhoFonteTxt+1 )+'px';        
      $("h4").css({ fontSize: tamanhoFonteTxt }); 

      var tamanhoFonteTxt = parseInt( $("h5").css( 'fontSize' ) );
      tamanhoFonteTxt = ( tamanhoFonteTxt+1 )+'px';        
      $("h5").css({ fontSize: tamanhoFonteTxt });                 

      var tamanhoFonteTxt = parseInt( $("h6").css( 'fontSize' ) );
      tamanhoFonteTxt = ( tamanhoFonteTxt+1 )+'px';        
      $("h6").css({ fontSize: tamanhoFonteTxt }); 

      var tamanhoFonteTxt = parseInt( $("p").css( 'fontSize' ) );
      tamanhoFonteTxt = ( tamanhoFonteTxt+1 )+'px';                                                     
      $("p").css({ fontSize: tamanhoFonteTxt });        

      var tamanhoFonteTxt = parseInt( $("span").css( 'fontSize' ) );
      tamanhoFonteTxt = ( tamanhoFonteTxt+1 )+'px';                                                     
      $("span").css({ fontSize: tamanhoFonteTxt }); 

      var tamanhoFonteTxt = parseInt( $(".fonte_acessibilidade").css( 'fontSize' ) );
      tamanhoFonteTxt = ( tamanhoFonteTxt+1 )+'px';                                                     
      $(".fonte_acessibilidade").css({ fontSize: tamanhoFonteTxt });         

  });
  //diminuit fonte
  $("#diminuirFonteTxt").click(function(){

      var tamanhoFonteTxt = parseInt( $("h1").css( 'fontSize' ) );
      tamanhoFonteTxt = ( tamanhoFonteTxt+1 )+'px';
      $("h1").css({ fontSize: tamanhoFonteTxt });

      var tamanhoFonteTxt = parseInt( $("h2").css( 'fontSize' ) );
      tamanhoFonteTxt = ( tamanhoFonteTxt-1 )+'px';        
      $("h2").css({ fontSize: tamanhoFonteTxt }); 

      var tamanhoFonteTxt = parseInt( $("h3").css( 'fontSize' ) );
      tamanhoFonteTxt = ( tamanhoFonteTxt-1 )+'px';        
      $("h3").css({ fontSize: tamanhoFonteTxt }); 

      var tamanhoFonteTxt = parseInt( $("h4").css( 'fontSize' ) );
      tamanhoFonteTxt = ( tamanhoFonteTxt-1 )+'px';        
      $("h4").css({ fontSize: tamanhoFonteTxt }); 

      var tamanhoFonteTxt = parseInt( $("h5").css( 'fontSize' ) );
      tamanhoFonteTxt = ( tamanhoFonteTxt-1 )+'px';        
      $("h5").css({ fontSize: tamanhoFonteTxt });                 

      var tamanhoFonteTxt = parseInt( $("h6").css( 'fontSize' ) );
      tamanhoFonteTxt = ( tamanhoFonteTxt-1 )+'px';        
      $("h6").css({ fontSize: tamanhoFonteTxt }); 

      var tamanhoFonteTxt = parseInt( $("p").css( 'fontSize' ) );
      tamanhoFonteTxt = ( tamanhoFonteTxt-1 )+'px';                                                     
      $("p").css({ fontSize: tamanhoFonteTxt });        

      var tamanhoFonteTxt = parseInt( $("span").css( 'fontSize' ) );
      tamanhoFonteTxt = ( tamanhoFonteTxt-1 )+'px';                                                     
      $("span").css({ fontSize: tamanhoFonteTxt }); 

      var tamanhoFonteTxt = parseInt( $(".fonte_acessibilidade").css( 'fontSize' ) );
      tamanhoFonteTxt = ( tamanhoFonteTxt-1 )+'px';                                                     
      $(".fonte_acessibilidade").css({ fontSize: tamanhoFonteTxt }); 

  });

  //contraste
  $("#contraste").click(function(){
      var cssFile = $('#contrasteCSS');
      if(!cssFile.attr('id')){
          $('head').append('<link id="contrasteCSS" rel="stylesheet" href="https:////www.pinhalgrande.rs.gov.br/css/contraste.css" type="text/css" />');
      }
  });
  //remover contraste
  $("#corOriginal").click(function(){
      $('#contrasteCSS').remove();
  }); 

  });  
  
  $(document).on("click", "#btn-noticias", function(){
    var value_p = $('.value_p').val();
    var ano_qual = $('.ano_qual').val();
    var conteudo = '<div class="row">';
      $.getJSON('https://www.novapalma.rs.gov.br/pages/noticias_api.php?p='+value_p+'&ano_qual='+ano_qual, function(res) {
        for(var i = 0; i < res.data.length; i++){
          conteudo += 
          '<div class="col-md-3 mb-4">'+
            '<div class="card shadow-sm">'+
              '<div style="background: url(' + res.data[i].img + ') no-repeat center center; background-size:cover;">'+
                '<a href="' + res.data[i].link + '" title="' + res.data[i].titulo + '">'+
                  '<img src="https://www.novapalma.rs.gov.br/images/spc.png" height="180px" alt="' + res.data[i].titulo + '" />'+
                '</a>'+
              '</div>'+
              '<div class="card-body">'+
                '<p class="card-text">' + res.data[i].titulo + '</p>'+
                '<div class="d-flex justify-content-between align-items-center">'+
                  '<div class="btn-group">'+
                    '<a href="' + res.data[i].link + '" class="btn btn-sm btn-outline-secondary" title="' + res.data[i].titulo + '">Veja mais</a>'+
                  '</div>'+
                  '<small class="text-muted">' + res.data[i].data + '</small>'+
                '</div>'+
              '</div>'+
            '</div>'+
          '</div>'; 
          $('.value_p').val(res.data[i].p);
        }
      conteudo += '</div>';
      $('.noticias').append(conteudo);
    }); 
  });   

  $(document).on("click", "#btn-fotos", function(){
    var value_p = $('.value_p').val();
    var conteudo = '<div class="row">';
      $.getJSON('https://www.novapalma.rs.gov.br/pages/fotos_api.php?p='+value_p, function(res) {
        for(var i = 0; i < res.data.length; i++){
          conteudo += 
          '<div class="col-md-3 mb-4">'+
            '<div class="card shadow-sm">'+
              '<div style="background: url(' + res.data[i].img + ') no-repeat center center; background-size:cover;">'+
                '<a href="' + res.data[i].link + '" title="' + res.data[i].titulo + '">'+
                  '<img src="https://www.novapalma.rs.gov.br/images/spc.png" height="180px" alt="' + res.data[i].titulo + '" />'+
                '</a>'+
              '</div>'+
              '<div class="card-body">'+
                '<p class="card-text">' + res.data[i].titulo + '</p>'+
                '<div class="d-flex justify-content-between align-items-center">'+
                  '<div class="btn-group">'+
                    '<a href="' + res.data[i].link + '" class="btn btn-sm btn-outline-secondary" title="' + res.data[i].titulo + '">Veja mais</a>'+
                  '</div>'+
                  '<small class="text-muted">' + res.data[i].data + '</small>'+
                '</div>'+
              '</div>'+
            '</div>'+
          '</div>'; 
          $('.value_p').val(res.data[i].p);
        }
      conteudo += '</div>';
      $('.fotosApi').append(conteudo);
    }); 
  });   

  $(document).on("click", "#btn-boletins", function(){
    var value_p = $('.value_p').val();
    var conteudo = '<div class="row">';
      $.getJSON('https://www.novapalma.rs.gov.br/pages/boletins_api.php?p='+value_p, function(res) {
        for(var i = 0; i < res.data.length; i++){
          conteudo += 
          '<div class="col-md-3 mb-4">'+
            '<div class="card shadow-sm">'+
              '<div>'+
                '<a href="' + res.data[i].link + '" title="' + res.data[i].titulo + '">'+
                  '<img src="' + res.data[i].img + '" alt="' + res.data[i].titulo + '" width="100%" />'+
                '</a>'+
              '</div>'+
              '<div class="card-body">'+
                '<div class="d-flex justify-content-between align-items-center">'+
                  '<div class="btn-group">'+
                    '<a href="' + res.data[i].link + '" class="btn btn-sm btn-outline-secondary" title="' + res.data[i].titulo + '">Veja mais</a>'+
                  '</div>'+
                  '<small class="text-muted">' + res.data[i].data + '</small>'+
                '</div>'+
              '</div>'+
            '</div>'+
          '</div>'; 
          $('.value_p').val(res.data[i].p);
        }
      conteudo += '</div>';
      $('.boletinsApi').append(conteudo);
    }); 
  }); 

})()
