move the JS to jQuery plugin. fix a minor bug.