converting script to fully jquery plugin