creating a jquery plugin

Refatoring the script to make a jquery plugin format.