Turns into a jQuery plugin

Had to tidy up code into different files and turned it into a plugin to
use with jQuery.