I have actually done something similar myself. Basicly the $header template is parased before almost all other templates, so that creates a slight problem.. You have 2 options here. You can make the functins and eval tempates parse before the the header template by placing the code ahead of the $header in global.php, or declare it in your phpinclude template.
Either way works, unfortunatly I don't know what code it is for $newposts.. Hopefully some one else does

I beleive the code is somewhere in functions.php, but again, I could be wrong