Revert "Clean up the JS and simplify it"

This reverts commit f8187d84404a302b7cff2483f806cac4af1863c7.
Clean up the JS and simplify it

Moved the JS to the bottom of the page (refer to commit
d9b0558fc6db7012f3fdb5cf498ec7f514c64f36 ). I removed the
$(document).ready because as the JS is at the bottom of the page the
page has “loaded” and so the elements can be referenced in the JS code.