Extensive transformation into a jQuery plugin