Cleanup of header.php

-Move some js functions to global.js
-Shift code for easier reading