MikroSight.com

MikroSight.com

| Home | NPA/NPX |

Google
Web
MikroSight

Weekly Image Script

See my NEW & Improved version of this script
well, at least one that can be customized easier!

This script calls a different image for each week of the year.  Images should be stored in a common folder and named  image1 through image52.  You can modify the script to use any folder, file name, or file extension. 

NOTE: Since 52 weeks is only 364 days, this script forces day 365 back to 364. Also, be aware that because this is JavaScript, the time used here is the current system time of the client's computer wherever they are in the world.

When you use this, and I know you will please consider making a small donation even $1 will help

I would appreciate you leaving my credits in the script when you use this.

<SCRIPT LANGUAGE="JavaScript" type="text/JavaScript">
<!-- Written by J.M. Royalty in 2002 - http://mikrosight.com/scripts/weeklyimage/weeklyimage.shtml -->
<!-- Begin
var now = new Date();
now.setHours(0,0,0,0); //set time to midnight 
var days = Math.round(now.valueOf() / 86400000); // each day is 86400000 milliseconds
var leapoff = Math.ceil((now.getFullYear() - 1972) / 4); // days for leap years since 1970
var doy = (days - leapoff) % 365 + 1; // convert days to day number in current year
if (doy == 365) {doy = 364}; // adjust DOY to even multiple of 7
var wk = Math.floor(doy / 7); // convert day of year to week number
if ((doy % 7) > 0) {wk += 1}; // switch on same weekday as first doy

var imagefilename = "image" + eval(wk) + ".gif" // convert week number to filename


// add path to imagefilename and change name/extension as necessary
imagefilename = "img/" + imagefilename
// -->
</script>

You can put the above script anywhere on the page, either in the <HEAD> section or the <BODY> section.   

Where you want the picture to be displayed, in a table cell, or anywhere on the page, you need to add the following lines.

<script language="JavaScript" type="text/JavaScript">
document.write('<img border="0" src="' + imagefilename + '" alt="weekly image">');
</script>