$(document).ready(function () {
  $('a[href^="#"]').click(function(e) {
    e.preventDefault();

    var position = $($(this).attr('href')).offset().top-100;

    $('body, html').animate({
      scrollTop: position
    }, 500);
  });

  $('.category').click(function () {
    $(this).toggleClass('minus');
    var siblings = $(this).siblings();
    $.each(siblings, function () {
      $(this).toggleClass('expand');
    });
  });
});

$(window).scroll(function () {
  /*console.log('helloooo');
  var contentPos = $('.content').offset().top - $('.content').css('margin-top').slice(0, 2);
  var leftHeight = $('.nav').height();
  var windowHeight = window.innerHeight;
  

  if ($(document).scrollTop() < contentPos) { // unfixes sidebar if scrolled back to top
    $('.nav').css({position: 'absolute', top: contentPos});
  }

  if ($(document).scrollTop() > contentPos) {
      $('.nav').css({position: 'fixed', top: '0'});
  }*/
  var position = $(this).scrollTop();
  var versions = $('.content .version-wrapper');
  $.each(versions, function() {
  	var firstTop = $(this).offset().top;
    var firstBottom = firstTop + $(this).height() -100;
    if (position > firstTop && position < firstBottom) {
  	  $(this).find('h1').addClass('fix');
    }
    if (position > firstBottom || position < firstTop) {
  	  $(this).find('h1').removeClass('fix');
    }
  });
  /*var firstTop = $('.content .version-wrapper').first().offset().top;
  var firstBottom = firstTop + $('.content .version-wrapper').first().height();
  if (position > firstTop && position < firstBottom) {
  	$('.content .version-wrapper').first().find('h1').addClass('fix');
  }
  if (position > firstBottom || position < firstTop) {
  	$('.content .version-wrapper').first().find('h1').removeClass('fix');
  }*/
});