Major refactor

Major refactor to use a standard modular jQuery plugin convention,
defining all functions as object literals.