//Changes the look of the page dependent on the local time.
//@author Michelle Steigerwalt <msteigerwalt.com>

//Let's put this in a closure so we don't step on any toes.
(function(){ 
	var lightsOut = function() {
		//Change the stylesheet.
		var lns  = document.getElementsByTagName('link');
		for (var i=0;i<lns.length;i++) {
			lns[i].href = lns[i].href.replace('day', 'night');
		}
		//Change every image that includes 'day' to 'night' instead.
		var imgs = document.getElementsByTagName('img');
		for (var i=0;i<imgs.length;i++) {
			if (imgs[i].src.indexOf('day')>-1){
				imgs[i].src = imgs[i].src.replace('day', 'night');
			} else if(imgs[i].src.indexOf('Day')>-1) {
				imgs[i].src = imgs[i].src.replace('Day', 'Night');
			}
		}
	};
	var h = new Date().getHours();
	//Lights go out between 9PM and 6AM.
	if (h > 20 || h < 6) { lightsOut(); } 
})();

