Moved javascript functions to their own .js

I hope nothing broke...