Extracted javascript. Added jsdoc sample comments.