/*!
 * Start Bootstrap - Grayscale Bootstrap Theme (http://startbootstrap.com)
 * Code licensed under the Apache License v2.0.
 * For details, see http://www.apache.org/licenses/LICENSE-2.0.
 */

// jQuery to collapse the navbar on scroll



$(window).resize(function() {
    if(this.resizeTO) clearTimeout(this.resizeTO);
    this.resizeTO = setTimeout(function() {
        $(this).trigger('resizeEnd');
    }, 0);
});

$(window).bind('resizeEnd', function() {
    collapseNavbar();
});

function menu_down(){
  $(".navbar-fixed-top").addClass("top-nav-collapse");
  $(".navbar-custom a").addClass("pintar-a");
  $("#logo-mobile").css("display", "inherit");
  $("#logo-desktop").css("display", "none");
  $("#menu-redes").css("height", "0");
}

function menu_up(){
  $(".navbar-fixed-top").removeClass("top-nav-collapse");
  $(".navbar-custom a").removeClass("pintar-a");
  $("#logo-mobile").css("display", "none");
  $("#logo-desktop").css("display", "inherit");
   $("#menu-redes").css("height", "auto");
}


// jQuery to collapse the navbar on scroll
function collapseNavbar() {
    var mediaquery_768_max = window.matchMedia("(max-width: 768px)");
    var mediaquery = window.matchMedia("(min-width: 768px)");
    var mediaquery_992 = window.matchMedia("(min-width: 992px)");
  
   if (mediaquery_768_max.matches) {
              $("#logo-mobile").css("display", "none");
              $("#logo-desktop").css("display", "inherit");
              $(".navbar-custom a").removeClass("pintar-a");
              $("#lista-menu").css("padding-top", "0.8em");

      }

    if (mediaquery_992.matches) {
        if ($(".navbar").offset().top > 0) {
           menu_down();
          $("#lista-menu").css("padding-top", "1.2em");
        }else{
           menu_up();
          $("#lista-menu").css("padding-top", "0");
        }  
    }else{
       if (mediaquery.matches) {
        if ($(".navbar").offset().top > 0) {
            menu_down();
            $("#lista-menu").css("padding-top", "0.6em")
        } else {
            menu_up();
            $("#lista-menu").css("padding-top", "0");

            $("#menu-redes").css("margin-bottom", "0");
        }
    }

  }
  
}


$(window).scroll(collapseNavbar);
$(document).ready(collapseNavbar);

// jQuery for page scrolling feature - requires jQuery Easing plugin-103
$(function() {
   var mediaquery_767 = window.matchMedia("(max-width: 767px)");
    $('a.page-scroll').bind('click', function(event) {
        var $anchor = $(this);

        if(mediaquery_767.matches){
            $('html, body').stop().animate({
             scrollTop: $( $(this).attr('href') ).offset().top
           }, 1500);
       }else{
            $('html, body').stop().animate({
             scrollTop: $( $(this).attr('href') ).offset().top-103
           }, 1500);
       }

    });
});

// Closes the Responsive Menu on Menu Item Click
$('.navbar-collapse ul li a').click(function() {
  if ($(this).attr('class') != 'dropdown-toggle active' && $(this).attr('class') != 'dropdown-toggle') {
    $('.navbar-toggle:visible').click();
  }
});