Rewritten as a jQuery plugin