Quantum mechanics of systems with a gauge group