Refactored as jQuery plugin
Reinstated event handlers into plugin.