Date - Daily Events

Repeat events daily at set times, any number of events can be set within the 24 hour period.
The script has a variety of uses from showing different images, text, redirection, running functions etc.

For this example I have set the script to display a different image on every hour from 10 am until 11pm, the active image will be shown at the same hour every day. Outside this period, 11pm to 10 am, the default image is shown.

Default Image

The relative information is held in an array, a typical index is as follows

[day,start time,end time,"image","Alt text","Image text"],

day - set to 7 to show every day or set to a number from zero to 6 to only show on that day
0 = sunday, 1 = monday, 2 = tuesday etc.
start time - Time to start showing the image
end time - Time to stop showing the image
image - Image to be shown
Alt Text - The alt text to be shown for the image
Image text - The text to show with the image

All times must be entered using the 24hr clock format

9 30am = 0930
9 30pm = 2130

Supposing you want to show image1 at 2 00pm every day for 2 hours except that on one specific day, say wednesday, you want to show image2 instead at the same time or for a period during that 2 hours

[7,1400,1600,"image1.jpg","The alt","The text"], // daily image

[3,1430,1530,"image2.jpg","The alt","The text"], // wednesday image

For the above image1 will start showing at 1400 then at 1430 image2 will be shown until 1530 then image1 finishes showing again until 1600

All daily events must come before any specific day events in the array.

A default image and text can be shown when no event is active.

<HTML>
<HEAD>
<TITLE>Date - Daily Events</TITLE>

<script type="text/javascript">
<!--
// jeff
// www.huntingground.freeserve.co.uk

// day, 7 = every day, 0 to 6 = specific day

dataArray=[ // day, start time, end time, image,text
[7,1000,1100,"pic10_tn.jpg","Alt Text","Image Text"],
[7,1100,1200,"pic11_tn.jpg","Alt Text","Image Text"],
[7,1200,1300,"pic12_tn.jpg","Alt Text","Image Text"],
[7,1300,1400,"pic13_tn.jpg","Alt Text","Image Text"],
[7,1400,1500,"pic14_tn.jpg","Alt Text","Image Text"],
[7,1500,1600,"pic15_tn.jpg","Alt Text","Image Text"],
[7,1600,1700,"pic16_tn.jpg","Alt Text","Image Text"],
[7,1700,1800,"pic17_tn.jpg","Alt Text","Image Text"],
[7,1800,1900,"pic18_tn.jpg","Alt Text","Image Text"],
[7,1900,2000,"pic19_tn.jpg","Alt Text","Image Text"],
[7,2000,2100,"pic20_tn.jpg","Alt Text","Image Text"],
[7,2100,2200,"pic21_tn.jpg","Alt Text","Image Text"],
[7,2200,2300,"pic02_tn.jpg","Alt Text","Image Text"] // no comma at the end of last index
]

defaultPic="default.jpg"
defaultText="Default Image"

function dailyCount(){
currentDate=new Date()
currentDay=currentDate.getDay()
currentHour=currentDate.getHours()
currentMin=currentDate.getMinutes()

if(currentHour<10){currentHour="0"+currentHour}
if(currentMin<10){currentMin="0"+currentMin}

currentTime=currentHour+""+currentMin
t=0
display=0

for(var i=0;i<dataArray.length;i++){

if((dataArray[i][0]==7||currentDay==dataArray[i][0])&&currentTime>=dataArray[i][1]&&currentTime<dataArray[i][2]){
index=i
display=1
}

if(display==1){
document.images["mypic"].src=dataArray[index][3]
document.images["mypic"].alt=dataArray[index][4]
document.getElementById("txt").innerHTML=dataArray[index][5]
}
else{
document.images["mypic"].src=defaultPic
document.getElementById("txt").innerHTML=defaultText
}

}

setTimeout("dailyCount()",1000)

}

// put onload="dailyCount()" in the opening BODY tag

// -->
</script> 
</HEAD>
<BODY onload="dailyCount()">

<img name="mypic" src="spacer.gif">
<div id="txt">Default Image</div>

</BODY>
</HTML>