What causes the Earth to have magnetic poles? A compass can tell me the directions of the Earth's North and South poles?  What is it about the Earth that produces this "polarity" such that a compass can pick it up?

The first thing that jumped into my head was the Earth's rotation, but if that is the explanation, why have I heard from people that the Earth's polarity can switch every million years or so?
Well, firstly it's important to recognise that the poles are merely the extremities of the shape of a magnetic field - the earth's magnetic field.  All magnetic fields have polarities as such.

However, you're asking why the field itself even exists, I gather.  In this case it's generated by electric currents in the conductive molten iron (and other metals) in the core of the earth, as a result of convection currents generated by escaping heat.   This is known as a geodynamo, and is one way of generating a magnetic field.  However, exactly why this occurs is still under investigation.

More is available in this Wiki piece - specifically on the physical origins of the earth's magnetic field.