rewrote script as a pluggable jquery plugin