Preheating of the Intergalactic Medium by Gravitational Collapse and Ultraviolet Background