fixed some bugs and rewrittin as jQuery UI Plugin