The Jahn-Teller effect and magnetism: transition metal compounds