converted JavaScript into jQuery plugin