Js cleanup

Tried as best as I could to cleanup the javascript in this (superb!) codebase a bit. It seems like you are focused on code quality, so I really think the JS-part should be as good as possible as well. Maybe I'm a bit outdated to use jsLint, but it seemed like you've written your js in a style that resembles js-lint.