Why do magnets lose their magnetism when heated?