Origin of the yarmulke?

My son just asked me some details about the wedding of a Jewish friend that I recently attended, and I had the same experience we all do occasionally of being embarrassingly ignorant. So where else to ask but here?

What is the origin of the Jewish tradition of wearing yarmulkes at religious occasions? What is it intended to signify, and when did it start? Why is its use restricted to men? And is it proper for gentiles to wear them at weddings?

Much obliged.

The Judaism 101 website says of the yarmulke:

Thank you muchly, MEB.

I would joke with my friends at hebrew school that it was what was left when they cut out the middle of hats to make visors.