Code cleanup.
Reformatted code improving readability, much more cleanup, made some variables global, optimized some jQuery usages, refactored some functions for consistency.