yes, the first error reason is improper mouse handling (e.g. using 2 mouse loops at the same time - one for main menu and another for the game level).
as I see, you do not create a new empty level for the main menu (this is the only reason why its panels remain visible). a load_level(NULL); could help when you call again your main menu.
or use higher layer value for your main menu panels to cover everything, if you want to keep the game level with its panels.
I also dislike templates
