PDA

View Full Version : Images by Day and Time



bokanegro
07-02-2008, 06:53 AM
Hi there, I am new hire and knowe that you can help me
Scrip name is: RADIO PROGRAM ON AIR

you can view this example but it's flash and I don't need flash script! http://www.rtl.it
http://www.dynamicdrive.com/dynamicindex17/freqcontent.htm

Problem:
This is my script:



function timeOfDayImage() {
var now = new Date;
var timeNow = now.getHours();
var img = null; var mess = '';
if (timeNow < 4 || timeNow > 20) {
img = 'time1.gif'; mess = 'night';
} else if (timeNow < 6) {
img = 'time2.gif'; mess = 'dawn';
} else if (timeNow < 8) {
img = 'time3.gif'; mess = 'early morning';
} else if (timeNow < 11) {
img = 'time4.gif'; mess = 'morning';
} else if (timeNow < 13) {
img = 'time5.gif'; mess = 'noon';
} else if (timeNow < 16) {
img = 'time6.gif'; mess = 'afternoon';
} else if (timeNow < 18) {
img = 'time7.gif'; mess = 'late afternoon';
} else {
img = 'time8.gif'; mess = 'sunset';
}
document.write('<img src="graphics\/'+img+'" width="200" height="80" alt="'+mess+'" title="'+mess+'" />');
}

it's javascript, and i call this script with


<script type="text/javascript">
timeOfDayImage();
</script>

This is basic change image script depend of time, and I want to use it on radio station for display program that other call ON AIR. Basically whole program schema is in images so when is 3pm it will display one image. when is 5pm another and that it....



But there is problem program schema isn't same for whole week, that means I have different images every day, not all but there is five that must be displayed on Sunday but on Monday it's different program....



So I need to add into this script, basically one more variable with days and I try to do that but script is crashing...



For all you this isn't very big problem so please help me if you can

jscheuer1
07-02-2008, 08:01 AM
You haven't made it precisely clear what gets displayed on which days. But you can probably work that out once I give you the basic idea.

The script you posted looks OK for what it does. And since it is already getting the hour from the date object, it could also get the day number (these are 0 through 6 for Sun through Sat).

So, if you can arrange it that the different days' images are in different folders, you could do something like so:


function timeOfDayImage() {
var now = new Date;
var timeNow = now.getHours();
var dayNum = now.getDay();
var img = null; var mess = '';
if (timeNow < 4 || timeNow > 20) {
img = 'time1.gif'; mess = 'night';
} else if (timeNow < 6) {
img = 'time2.gif'; mess = 'dawn';
} else if (timeNow < 8) {
img = 'time3.gif'; mess = 'early morning';
} else if (timeNow < 11) {
img = 'time4.gif'; mess = 'morning';
} else if (timeNow < 13) {
img = 'time5.gif'; mess = 'noon';
} else if (timeNow < 16) {
img = 'time6.gif'; mess = 'afternoon';
} else if (timeNow < 18) {
img = 'time7.gif'; mess = 'late afternoon';
} else {
img = 'time8.gif'; mess = 'sunset';
}
document.write('<img src="graphics\/day'+dayNum+'\/'+img+'" width="200" height="80" alt="'+mess+'" title="'+mess+'" />');
}

Then the images for Sunday could be in:

graphics/day0/

for Monday:

graphics/day1/

and so on. But this is client side code, so if the user's clock is off or if they are in a different timezone, things will not work out as expected. You could (if you have a server side language available to you) use the server's time. Or you could use UTC time in javascript, that would make things work out if the user's clock is accurate.

However, an all server side solution would be better, as it wouldn't even require that the user have javascript enabled.

Then there is the matter of what happens when the time/program changes and the user hasn't refreshed the page. That would probably need to be done using javascript, but I won't worry about that now.

bokanegro
07-02-2008, 08:50 AM
That was fast

thank you, jscheuer1...

I don't have to worry about time zone because radio have one language and one country only Serbia ... so all users have same time...

Sorry about post in DD, first time error... I will be more carefull next time

anyway thanks for help