Refactor mainjs

move animation code into separate function, add in preventDefaults to fix js load bug on chats page