Refactoring main.js

Moved page-specific javascript from main.js to the page itself.