Refactored JavaScript

* put code into closure to avoid potential intermixing with other scripts
* stored reused jQuery calls into variables to speed things up