Rewrite script in jQuery.