Ref #286, Simplifies the javascript code and fixes an animation code.