Rewritten to become a jQuery plugin.