Agreed.  Move this to an external .js, not least so it will cache.