Optimize index.js and add style consistency

Declared all jQuery objects once where needed instead of diving into the DOM multiple times for the same object.

Added style consistency between variable declarations, if/else statements and functions.
if we already have access to `$` as jQuery, we could just use `$.fn[sr]`