bcs all Javascript should always be in a separate file. It is easier to maintain and also it is easier for browser to cache it, not to mention it is easier to debug it on development. I have also used module pattern here to keep the global namespace clean.