There's enough JS in here to put in a separate file. Separation of concerns and all that :)