let menuOpen = false;
let hamburger = $(".hamburger");

/*
 * Open navigation menu, change Hamburger icon to selected state
 * and display the back button overlay over the page
 */

function openNav() {
    $.selector_cache('#sidenav').addClass("sidenav-open");
    enableHamburger();
    menuOpen = true;
}


/*
 * Close navigation menu, change Hamburger icon back to default state
 * and hide the back button overlay
 */
function closeNav() {
    $.selector_cache('#sidenav').removeClass("sidenav-open");
    disableHamburger();
    menuOpen = false;
}


/*
 * Toggle the navigation bar
 */
function toggleNav() {
    if (menuOpen) {
        closeNav();
    } else {
        openNav();
    }
}

function disableHamburger() {
    $.selector_cache('.hamburger').removeClass("change");
}

function enableHamburger() {
    $.selector_cache('.hamburger').addClass("change");
}

// Animate hamburger on hover
$.selector_cache('.hamburger').hover(function(){
    $.selector_cache('.bar1').css("background-color", "#e62b1e");
    $.selector_cache('.bar2-1').css("background-color", "#e62b1e");
    $.selector_cache('.bar2-2').css("background-color", "#e62b1e");
    $.selector_cache('.bar2-1').css("left", "-5px");
    $.selector_cache('.bar2-2').css("right", "-5px");
    $.selector_cache('.bar3').css("background-color", "#e62b1e");
}, function(){
    $.selector_cache('.bar1').css("background-color", "#404040");
    $.selector_cache('.bar2-1').css("background-color", "#404040");
    $.selector_cache('.bar2-2').css("background-color", "#404040");
    $.selector_cache('.bar2-1').css("left", "0");
    $.selector_cache('.bar2-2').css("right", "0");
    $.selector_cache('.bar3').css("background-color", "#404040");
});
