Dogmatic refactoring and optimisation

- Removed as many calls to the jQuery selector as possible
- Generally attempted to improve readablility and conciseness
- Added genuine events for on_first_frame and on_last_frame handlers to bind to
- Use 'on' where available, 'bind' where not.