Stop creating JS in loops

Moved JS to buttons.js
Used better event binding to attach event handlers
Used to module patern to organize & structure code