I'm in the process of rewriting it once again to be specific on the change from night / day and so on to be time exact for the northern hemisphere. Also keep in mind I'm old school and not up to date expert on the latest and / or greatest coding and so on but this works for me.
Please hold any negative criticism please. I wrote this in notepad and coded it all by hand.
http://www.abeagleworld.com/download/head.txt