Separate JavaScript code out into its own JS file.
Various changes suggested by http://jslint.com/ and http://jshint.com/.