re-wrote JavaScript loading so it loads after the DOM and CSS are loaded as suggested by Tim