$(document).ready(function() {

/* Handy script from Soh Tanaka (http://is.gd/5LSkR) turns off the sticky sidebar if navigation is too long for the viewport */

    function staticNav() {
        var sidenavHeight = $("#nav").height(); //Get height of sidenav
        var winHeight = $(window).height(); //Get height of viewport

        if (sidenavHeight > winHeight) { //If sidenav is taller than viewport...
            $("#nav").css({'position' : 'static'}); //switch the fixed positioning to static. Say good bye to sticky nav!
            $("#wrapper").css({'background-attachment' : 'scroll'});
        }
    }
    staticNav(); //Execute function on load
    $(window).resize(function () { //Each time the viewport is adjusted/resized, execute the function
        staticNav();
    });
});