Okay for those that are actually wondering that is called a flehmen response. Horses and other animals (snakes for one) have a thing called a Vomeronasal organ (Jacobs organ) it is in the palette and is primarily there to detect pharmones. Culling the upper lip helps pass air over the organ letting them smell with it.