var today = new Date();
var endToday = new Date(today.getFullYear(),today.getMonth(),today.getDate(),23,59,59,999);
var jan1 = new Date(today.getFullYear(),0,1);
var dec31 = new Date(today.getFullYear(),11,31,23,59,59,999);

//How much of the year will have passed at midnight? (0 = start, 1 = end)
var yearGone = (endToday.getTime() - jan1.getTime()) / (dec31.getTime() - jan1.getTime()); 

//How much of the day has passed? (0 = start, 1 = end);
var dayGone = (86400000-(endToday.getTime() - today.getTime()))/86400000; 

//This approximates the change in sunset times over a year in the UK. If you were to graph this, x=yearGone.
var sunsetPoint = (Math.sin(2*Math.PI*yearGone - Math.PI/2)/9)+0.77; 

//Create a new link to a CSS file
var css  = document.createElement('link');
css.rel = 'stylesheet'
css.type = 'text/css';

//If we're before sunset, show the day background. Otherwise, show night.
if(dayGone < sunsetPoint) 
	css.href = '/wp-content/themes/fwc/css/backgrounds/'+style+'-day.css';
else
	css.href = '/wp-content/themes/fwc/css/backgrounds/'+style+'-night.css';
document.getElementsByTagName('head')[0].appendChild(css);
