javascript api codes rewritten as jQuery plugin