In order to play the music off of the top of your head, you need to know how to memorize all the notes.
Some can memorize the notes in a matter of minutes, some can do it in several hours.
There are a few things you can do to help improve your memory:
1. Sleeping can give you a better memory. Look at the notes first, play it over several times, then go to sleep.
2. Know the melody of the song.
3. Look at the keyboard when you play and study your hand movements.
4. This is the old school way: Play the song over and over and over and over... Until you feel like you can play it without even thinking about playing. (This process takes about a week)
There are a lot more things you can do, but I think those are the essential ones.