From the 2013 Wendelstedt Rules and Interpretations Manual (p.139):
The top of an outfield fence is out of play; however, any part of the facing of the fence is not. If a ball hits the fence, clearly on its facing, it is no longer in flight and the award would not be four bases. However, if the ball hits an area at the top of the fence, if it continues over the fence into a dead ball or spectator area, it should be adjudged as hitting the top of the fence. If, though, it does not continue over the fence, but instead, immediately returns to the playing field, it should be adjudged as never leaving the playing field. It would be left in play.
If a fielder grabs a ball on top of the fence before it has stopped, or before it has continued into a dead ball area, the ball will be alive and in play. Should the ball stop on top of the fence, the award will be four bases, as the ball is out of play.