let el = document.getElementById('nav');
let nav = $('.nav-open');
let navContainer = $('.nav-container');
$(function () {
    $('#nav').prop('checked', false);
    $('body').css('overflow', '');
    nav.removeClass('open');
    nav.addClass('close');
});

$('ul li a', navContainer).on('click', function () {
    $('input[id=nav]').prop('checked', false);
    $('body').css('overflow', '');
    nav.removeClass('open');
    nav.addClass('close');
});

nav.on('click', function () {
    if (nav.hasClass('open')) {
        $('body').css('overflow', '');
        navContainer.css('display','none');
        nav.removeClass('open');
        nav.addClass('close');
    } else {
        $('body').css('overflow', 'hidden');
        navContainer.css('display','block');
        nav.removeClass('close');
        nav.addClass('open');
    }
});

if (document.querySelector('.sub-menu:not([data-ignore-scroll])')){
    let articles = $('article')
        , sticky = $('.sub-menu')
        , nav_height = nav.outerHeight();

    $(window).on('scroll', function () {
        let cur_pos = $(this).scrollTop();
        articles.each(function() {
            let top = $(this).offset().top - nav_height,
                bottom = top + $(this).outerHeight();
            if (cur_pos + 150  >= top && cur_pos + 150 <= bottom) {
                sticky.find('a').removeClass('active');
                sticky.find('a[href="#'+$(this).attr('id')+'"]').addClass('active ');
            }
        });
    });
}