fixed some bugs and rewritten as jQuery UI Plugin