I made myself an electromagnet and did a small experiment involving it and a permanent magnet. When I switched on the electromagnet it attracted the permanent magnet. I made the assumption that they were opposite poles, hence making them attract. However, I changed the current direction of the electromagnet thinking that it would then repel the permanent magnet. However, it also attracted the permanent magent. This has left me highly confused about the polarity of magnets. Can someone please help?