Cleanup js and fix navigation

The commits should be self-explanatory. I've tested this lightly in firefox and chrome and it seems to behave well. I couldn't figure out how to use [`jQuery.fn.on`](https://api.jquery.com/on/) with the  [`window.onpopstate`](https://developer.mozilla.org/en-US/docs/WindowEventHandlers.onpopstate) event, so that event's just plain old javascript + the browser API.