//Rotate multiple images in one image location within the document.
//Enlarge an image into the window.

//Requires the following lines in the HTML document.
//A call to load this script.
//	<SCRIPT language=JavaScript src="../../../ImageWorks.js"></SCRIPT>
//A call to the routine that sets up the images ready to rotate.
//	<body onload="SaveSrc()">
//A division in which to place the elarged picture.
//	<div id="ZoomDiv" onclick="CloseZoomWin()"
//	style="VISIBILITY: hidden; POSITION: absolute; background=white; border:solid; border-width:10; border-color:f0f0f0">
//	<img id="ZoomImg" src title="Click to close"><br>
//	<center>Click to close</center>
//	</div>
//A note to the viewer about enlarging the pictures.
//	<p align="right"><font size="2" color="#800080">Click on an image to magnify it (JavaScript is required).</font>

var timerID = null	//To remember the timer interval ID.

//Call this routine from the BODY tag; <body onload="SaveSrc()">
//For the multiple rotating images effect, the multiple image locations (SRC) must be stored in the IMG tag.
//The SRC shows the first image as normal. Other image locations are stored in SRC1, SRC2 etc. parameters.
//This saves the original SRC value because the SRC parameter will be used to display other of the multiple images.
function SaveSrc() {
	for (img=0; img < document.images.length; img++) {		//Check each image in the document.
		if (document.images[img].src1) {		//The presence of the 'src1' parameter indicates that there are multiple images to display.
			sx = 2
			while (eval("document.images[img].src" + sx)) {	//If it exists then look at the next one.
				sx ++
			}
			eval("document.images[img].src" + sx + "=document.images[img].src")	//Save the original SRC in a new property value because it will get over-written when the image is rotated.
			document.images[img].style.filter="progid:DXImageTransform.Microsoft.Fade(Duration=1.5)"
		}
	}
	//This calls the SwitchImage routine every 3 seconds to rotate the images around.
	timerID = setInterval("SwitchImage()", 4000);
}




//Rotate multiple images in one image location within the document.
//Image width and height are defined in the <IMG> tag and will not be changed. Images of different dimentions may be entertained by omitting WIDTH, HEIGHT oe both parameters from the IMG tag.
//To avoid document reformatting put the IMG tag in a table large enough to fit all images.
//<table align=right width=240 height=160><tr><td><IMG....></td></tr></table>
//To define the extra images to display add 'srcN=""' parameters to the IMG tag;
//<img src="image1.jpg" src1="image2.jpg" src2="image3" srcN="imageN+1.jpg" title="Click to zoom" align="right" onclick="OpenZoomWin(this)" width="200" height="150" border="10" style="border-color:f0f0f0">
//
function SwitchImage() {
	for (img=0; img < document.images.length; img++) {		//Check each image in the document.
		if (document.images[img].src1) {		//The presence of the 'src1' parameter indicates that there are multiple images to display.
			if (document.images[img].offsetParent.tagName == "BODY") {	// offsetTop measures from the parent object. This might be TD rather than BODY
				onScreen = ((document.images[img].offsetTop > document.body.scrollTop - document.body.clientHeight)
					&& (document.images[img].offsetTop < document.body.scrollTop + document.body.clientHeight));
			} else { if (document.images[img].offsetParent.tagName == "TD") {	// offsetTop measures from the parent object. This might be TD rather than BODY
				onScreen = ((document.images[img].offsetParent.offsetTop > document.body.scrollTop - document.body.clientHeight)
					&& (document.images[img].offsetParent.offsetTop < document.body.scrollTop + document.body.clientHeight));
			}}
			if (onScreen == true) {
					// Only affect images that are visible in the browser window
				document.images[img].filters(0).Apply();
				document.images[img].filters(0).Play();
				if (eval("document.images[img].src" + (document.images[img].srcx + 1))) {		//If there is another image in the sequence to display then select it.
					document.images[img].srcx ++
				}
				else {		//If there are no more images in the sequence then start back at 1.
					document.images[img].srcx = 1
				}
				if (document.images[img]) {		//This might be a pointless check???
					document.images[img].src = eval("document.images[img].src" + document.images[img].srcx)
				}
			}
		}
		//Tidy up the filename to use as a title.
		bits = document.images[img].src.split("/")
		fn = bits[bits.length - 1].split(".")
		if (fn[0].substr(4,1) == "_") {
//		picTitle = fn[0].substr(5).replace(/[A-Z]/g)
			document.images[img].title = fn[0].substr(5)	// + "\nClick to zoom"
		}
	}
}




//When an image is clicked on, this puts it into a DIVision in the top left of the window at the images full height and width.
//Images can then be squashed down to fit more neatly on the page with the text but can be enlarged for closer viewing.
function OpenZoomWin(objImg) {
	clearInterval(timerID);	//Stop the pictures from flipping while examining a picture.
	ZoomImg.src = objImg.src
	document.all.ZoomDiv.style.posTop = document.body.scrollTop + 10
	document.all.ZoomDiv.style.posLeft = 10
	ZoomDiv.style.visibility = "visible"
}

//This is just to hide the DIVision and image so that the rest of the text can be seen again.
function CloseZoomWin() {
	ZoomImg.src = ""
	ZoomDiv.style.visibility = "hidden"
	timerID = setInterval("SwitchImage()", 3000);
}


function IMGinfo(img) {	// For debugging.
	alert(img.srcx)
	sx = 1
	rpt = ""
	while (eval("img.src" + sx)) {
		rpt = rpt + "\nSRC" + sx + " = " + eval("img.src" + sx)
		sx ++
	}
	alert(rpt)
}

