/***********************************************************************************\
|***********************************************************************************|
|* Avast ye scallewags! A script to be changin' yon image based upon ye hourglass! *|
|***********************************************************************************|
\***********************************************************************************/


// This be your list of images and the START TIMES to use them. The first two sub-
// elements of each position in the array is the hour and the minute in military time.
// So (00, 00) refers to midnight, and (18, 30) refers to 6:30pm. These MUST be kept
// in chronological order or else bad things will happen!.
var imgList =
[
// Hr Min The image to use at that time
[02, 03, "http://i485.photobucket.com/albums/rr216/btballenger/secrettime.jpg"],
[01, 04, "http://i485.photobucket.com/albums/rr216/btballenger/latenight.jpg"],
[04, 00, "http://i485.photobucket.com/albums/rr216/btballenger/predawn.jpg"],
[05, 30, "http://i485.photobucket.com/albums/rr216/btballenger/dawn.jpg"],
[06, 30, "http://i485.photobucket.com/albums/rr216/btballenger/sunrise.jpg"],
[07, 00, "http://i485.photobucket.com/albums/rr216/btballenger/morning.jpg"],
[09, 00, "http://i485.photobucket.com/albums/rr216/btballenger/day.jpg"],
[14, 00, "http://i485.photobucket.com/albums/rr216/btballenger/afternoon.jpg"],
[16, 00, "http://i485.photobucket.com/albums/rr216/btballenger/evening.jpg"],
[17, 30, "http://i485.photobucket.com/albums/rr216/btballenger/sunset.jpg"],
[18, 00, "http://i485.photobucket.com/albums/rr216/btballenger/earlynight.jpg"],
[23, 00, "http://i485.photobucket.com/albums/rr216/btballenger/latenight.jpg"],
];

// Figure out the current time.
var currDate = new Date();
var currHrs = currDate.getHours();
var currMins = currDate.getMinutes();

// Keep running track of which image is the best one to use
var bestImg = "";

// For each index in the list
for(idx in imgList)
{
// If this represents a valid time (hours between 0 and 24, minutes between 0 and 60...
if(imgList[idx][0] >= 0 && imgList[idx][0] < 24 && imgList[idx][1] >= 0 && imgList[idx][1] < 60)
{
// Then if the current time is later than the time we're looking at, we've found a better candidate!!
if(currHrs > imgList[idx][0] || currHrs == imgList[idx][0] && currMins >= imgList[idx][1])
bestImg = imgList[idx][2];
}
}

// If we haven't found ANY candidate image yet, then midnight wasn't defined. So we wrap around the
// clock and pick the absolute latest time.
if(bestImg == "")
bestImg = imgList[imgList.length - 1][2];

// Set the image using fancy Javascript
document.getElementById("top_bar").style.background = "url(" + bestImg + ")";