Why Do We Yawn?

We yawn a lot when we're tired or warm, and sometimes we even yawn just because we see other people yawning! But why do we yawn in the first place?