Converted code to a jQuery plugin.