use jquery instead of javascript

took a lonnnnnnnnnnnng time for this file.
More optimization and rationalization needed!
+ extensive tests