main menu javascript refactor