menu system

taken from BitWars - complicated but works fine :D