Re-implementation of javascript based on jQuery.