Refactored the script into a jQuery plugin