moved JS code into a jquery plugin