Convert script in jQuery plugin