Refine source code

1. Remove redundant global variables
2. Use jQuery instead of browser DOM API for consistancy
3. Refine query behaviors