converted to a jQuery plugin

This is one of those things that works great as a jQuery plugin