how does it know if it is going to fog up??
Temperature and perhaps humidity sensors.
Recirculated air traps humidity inside the car and leads to fogged windows if the temp/humidity is right.
Some cars also use carbon monoxide or nitrogen oxide sensors to monitor interior air quality. I don't know if the Focus has one or not. In this case, you really do want that outside air when the sensor says so...