	// set up globals

	var loadDate = new Date();		// date page was loaded
	var movieImages = new Array();		// to hold list of movie images and display times

	//
	// Object to hold the url of the image and the datetime it should be displayed
	//
	function movieImage (imageURL, displayDateStr)
	{
		this.imageSrc = "http://unbecominglevity.blogharbor.com/ntm/" + imageURL;
		this.displayDate = new Date(Date.parse(displayDateStr));
	}

	//
	// Resets the load date and renders the name-that-movie table again.
	//
	function refreshNTM()
	{
		loadDate = new Date();
		return(renderNTM());
	}

	//
	// Accepts a Date object d, and returns a string of the form: "H:MM AP"
	// where H is the hour (1 or 2 digits), MM is the minute, and AP is either
	// AM or PM (12-hour-format).
	//
	function getFriendlyTime(d)
	{
		var H = d.getHours();
		var M = d.getMinutes();
		var ampm = " AM";

		if (H>12)
		{
			H=H-12;
			ampm = " PM";
		}

		if (H==0)
		{
			H=12;
		}

		var hStr = "" + H;

		var mStr = "" + M;

		if (mStr.length == 1)
		{
			mStr = "0" + "" + mStr;
		}

		return (hStr + ":" + mStr + ampm);
	}
	
	//
	// Called when user mouses over an image link, resets the SRC of image 1 to the
	// SRC of the image link being rolled over.  Allows users to see the images
	// without having to pop them up in a new window.
	//
	function setImage(x)
	{
		document.getElementById('NTM_IMAGE').src = movieImages[x].imageSrc;
		return(true);
	}

	//
	// Builds the contents of the main DIV tag on the NTM page, the primary image,
	// the image times and links for images 2 through whatever, the "That's all
	// folks!" message when all images are up, and the refresh button.
	//
	function renderNTM()
	{
		// to cut down on concatenation statements (which are dog slow), we'll
		// push strings into an array and then join it at the end.

		var output = new Array();

		// table opener, primary image

		output.push("<TABLE cellSpacing=0 cellPadding=8 border=1><TBODY><TR>");
		output.push("<TD align=middle><STRONG><IMG ID=NTM_IMAGE src='");
		output.push(movieImages[0].imageSrc);
		output.push("' onMouseOver='setImage(0)';)>&nbsp;<BR><BR>");

		// Loop through images from second to last, build a string that shows
		// the image number and the time it becomes available.
		//
		// if the image is not available, include no link, and gray out the text:
		//	<FONT COLOR=GRAY>H:MM AP: ...image N...</FONT><BR><BR>
		//
		// if the image IS available, make the link available, and no graying:
		//	H:MM AP: ...<A href='img_url' target=_blank
		//		 onMouseOver='setImage(N);'
		//		 onMouseOut='setImage(0);'>image N</A>...<BR><BR>
		//
		// Image availability is determined by comparing the display datetime
		// of the image to the load datetime of the page.

		for (i=1; i<movieImages.length; i++)
		{
			var friendlyTime = getFriendlyTime(movieImages[i].displayDate);

			var fontOpen = "<FONT COLOR=GRAY>";
			var fontClose = "</FONT>";
			var linkOpen = "";
			var linkClose = "";

			if (loadDate >= movieImages[i].displayDate)
			{
				fontOpen = "";
				fontClose = "";
				linkOpen = "<A href='" + movieImages[i].imageSrc + "' target=_blank onMouseOver='setImage(" + i + ");' onMouseOut='setImage(0);'>";
				linkClose = "</A>";
			}

			output.push(fontOpen);
			output.push(friendlyTime);
			output.push(": ...");
			output.push(linkOpen);
			output.push("image ");
			output.push(""+(i+1));
			output.push(linkClose);
			output.push("...");
			output.push(fontClose);
			output.push("<BR><BR>");
		}

		// if all images available at this point, put out the final message.

		if (movieImages[movieImages.length-1].displayDate <= loadDate)
		{
			output.push("That's all folks!");
		}

		// close up the table and include refresh button

		output.push("</STRONG></TD></TR><TR><TD align=center><INPUT TYPE='BUTTON' VALUE='Refresh' OnClick='refreshNTM();' TITLE='Current as of ");
		output.push(loadDate.toString());
		output.push("'></TD></TR></TBODY></TABLE>");

		// get the NTM DIV and populate it with the contents of the output
		// array converted to string and concatenated together.

		var ntmDiv = document.getElementById("NTM_DIV");
		ntmDiv.innerHTML = output.join("");

		return(true);
	}
