
/* WHEELIE-BIN REMINDER

   When page is loaded, these functions wheel a bin across top of 
   screen (right to left) in the 24 hours to 6 a.m. on the day 
   of your fortnighly recycling garbage collection.
   E.g. if your collection is on a Wednesday morning
   the graphic will appear from 6 a.m. Tuesday to 6 a.m. Wednesday 
or,
   for the entire week, Sunday to Saturday.  
*/

/* NOTES 
The HTML document using this script must have in its HEAD Section:
  - a link to the separate cross-browser API script (api.js) 
  - a link to this script file 

The image is asumed to be in a DIV named "mi" in the HTML document.
In the example HTML file it is near the end of the BODY section.

In this example the wheelieBin() function is invoked after the closing 
</body> tag. This is instead of using <body... onLoad =...> which 
can be troublesome in IE4.       
*/


/* IMPORTANT : CONFIGURE FOR YOUR LOCAL COLLECTION DAY
   Set the reference date here (any past recycling collection date, 
   e.g. the most recent one)
*/

todayDateSim = "February 10, 2002 12:00:00";
startdate = "July 24, 2003 00:00:01";

// Configure wheelie speed and path, if required
startX = screen.width-30; // start at right edge
startY = 2;
stepX = -7; // In this case, movement left 
stepY = 0; // In this case, movement is horiz only, so no Y change  
endX = 5;   
endY = 2; // No change
delay = 2; // Bigger number = slower speed
keep = 1; // 1/0: bin stays parked after animation, or goes away 

/* All configuration as above; nothing in the functions below 
should need to be changed
*/

function wheelieBin()
{
refdate = new Date(startdate);
//todaydate = new Date(todayDateSim);
todaydate = new Date(); //defaults to today and now
var fortnight = 60 * 1000 * 60 * 24 * 14; //in milliseconds
var thirteendays = 60 * 1000 * 60 * 24 * 13;
var sevendays = 60 * 1000 * 60 * 24 * 7;
var nothing=0;
refdateMs = refdate.getTime(); //Refdate & time in milliseconds
todaydateMs = todaydate.getTime(); //Today's date and time in milliseconds
diff = todaydateMs - refdateMs;

if (diff % fortnight >= sevendays) // allows a week from Sun to Sat
	{
	div = gE("mi"); //get cross-browser element
	sX(div,startX); //Set initial x-posn
	sY(div,startY);  //Set initial y-posn
	bintimer = setTimeout ("moveBin()", delay)	
	sE(div)// Make visible
	}
}

function moveBin() 
{
div = gE("mi"); //get cross-browser element
currentX = gX(div);
currentY = gY(div); 
if (currentX > endX || currentY > endY) // End position not reached
	{
	sX(div,currentX + stepX);
	sY(div,currentY + stepY); 
	bintimer = setTimeout ("moveBin()", delay)
	// call this function recursively
	}
else //End reached 
	{ 
	hE(div);
	if (keep == 1)
		{  	
		div2 = gE("mi2"); // ref to 2nd image div
		sE(div2); //Hide original; show upright bin
		}
	}
}

