Jig is up

Does anyone know the origin of the phrase "the jig is up"?