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.
I'd add `undefined` as a third argument here (but not include it in the last line)