Similar comment as the css, this is a large enough chunk of code that would probably be better in its own .js (also fine for now..)