	// JS FILE FOR RUNNING STANDARD SLIDESHOW UNDER MOSAIC
	// ***************************************************
	// Place slideshow's own images (ie. Autorun, Stop buttons etc..) in the /images folder
	// *****
	// ensure XSL provides following hidden fields between <form name="sideform"></form> tags:
	//		(1) for total number of images:
	//		<input type="hidden" value="IMAGE01.jpg" name="image10"></input>
	//		<input type="hidden" value="Image 01 Caption" name="caption10"></input>
	//		etc..
	//		(2) relative path where the slideshow images are stored eg:
	//		<input type="hidden" name="approot" value="slideshowimages/" />
	//		(3) total number of (main-thumb) image pairs eg:
	//		<input type="hidden" name="totpics" value="8/" />
	
	var totpics;
	var caption1, caption2, caption3, caption4, caption5, caption6, caption7, caption8, caption9, caption10;
	var picnum=1;
	var totthumbs=5;
	var spacerimage="images/generic/spacer.gif";
	var thumboffset=0;
	var thumbstart,thumbfin;	
	thumbstart=1;
	thumbfin=totthumbs;
	var theTimeout;
	var do_autorun=-1;
	
	function initialise()  {

		doc=document.slideform;
		totpics=doc.totpics.value;
		document.getElementById('prevbutton').style.visibility="hidden"; 
		if (totpics>0)   {	
			approot=doc.approot.value;
			if (totpics==1)   {	
				document.getElementById('nextbutton').style.visibility="hidden"; 
				document.getElementById('autorunbutton').style.visibility="hidden";
				}
			if (totpics < 5) totthumbs=totpics;		

			// SET DATA: TOP CAPTION TEXT, HIDE CAPTIONS, IMAGES AND THUMBNAILS
			for (x=1;x<=totpics;x++)   {
				ic=x-1;
				eval("caption"+x+"=doc.caption"+x+".value;");
				eval("imagefilename=\"SS_\"+doc.image"+x+".value;");
				eval("mainimage"+ic+"=new Image();"); 
				eval("mainimage"+ic+".src=approot+imagefilename;"); 

				eval("thumbfilename=\"ST_\"+doc.image"+x+".value;");
				eval("thumbimage"+ic+"=new Image();"); 
				eval("thumbimage"+ic+".src=approot+thumbfilename;"); 

				if (x<6)  { eval("document.getElementById('thumb"+x+"').src=approot+thumbfilename;");	}
				if (x==1)   {
					document.getElementById('bottomnum1').style.color="#ffffff";
					document.getElementById('bottomTD1').style.backgroundColor="#990000";
					document.getElementById('bottomTD1').style.textAlign="center";
					document.getElementById('captiontext').innerHTML=caption1;
					}
				else   {
					eval("document.getElementById('bottomnum"+x+"').style.color='#000000';");
					eval("document.getElementById('bottomTD"+x+"').style.backgroundColor='#ffffff';");
					eval("document.getElementById('bottomTD"+x+"').style.textAlign='center';");
					}
				}
			}
		else   {
			document.getElementById('nextbutton').style.visibility="hidden"; 
			document.getElementById('autorunbutton').style.visibility="hidden";
			totthumbs=0;		
			document.getElementById('captiontext').innerHTML="Photo slideshow coming soon...";
			document.getElementById('mainpic').src=spacerimage; 
			}

		// enclose first thumb in brackets and give dark border, give all other thumbs a white border
		for (x=1;x<=totthumbs;x++)   {
			if (x==1)   {
				eval("document.getElementById('thumb"+x+"').style.borderColor='#333333';");
				eval("document.getElementById('LHbrack_tn"+x+"').src='images/generic/slide-LHbracket.gif';");
				eval("document.getElementById('RHbrack_tn"+x+"').src='images/generic/slide-RHbracket.gif';");
				}
			else   { eval("document.getElementById('thumb"+x+"').style.borderColor='#ffffff';"); }
			}
		}

	function toggle_autorun()  {
		do_autorun=0-Number(do_autorun);
		if (do_autorun==1)   { 
			autorun(); 
			document.getElementById('autorunbutton').src="images/generic/slide-autorun-stop.gif";
			document.getElementById('autorunbutton').alt="Click here to stop the slideshow";
			}
		else   { stop_autorun(); }
		}

	// run the slideshow !
	function autorun()   {
		// if next one is pic1 again need to do special bit of code since this action (going back to the beginning)
		// does not occur normally (Next Button would be hidden!) 
		if (picnum==totpics)   { 
			picnum=1; 
			thumboffset=0;
			eval("document.getElementById('bottomnum"+totpics+"').style.color='#000000';");
			eval("document.getElementById('bottomTD"+totpics+"').style.backgroundColor='#ffffff';");
			eval("document.getElementById('LHbrack_tn"+totthumbs+"').src='"+spacerimage+"';");
			eval("document.getElementById('RHbrack_tn"+totthumbs+"').src='"+spacerimage+"';");
			change_pic("num","1","");
			}
		else  { change_pic("next",picnum,""); }
		theTimeout=setTimeout("autorun();",3000);
		}

	// func needed when user clicks on main pic to stop autorun!
	function stop_autorun()  {
		do_autorun=-1;
		clearTimeout(theTimeout);
		document.getElementById('autorunbutton').src="images/generic/slide-autorun.gif";
		document.getElementById('autorunbutton').alt="Click here to run the slideshow!";
		}

	function change_pic(action,thepicnum,ctype)   {

		// dont do anything if number of pics = 1
		if (totpics>1)   { 
				
			// need to take into account that the thumbnails will always request picnums 1-5!
			if (ctype=="thumb")  { thepicnum=Number(thepicnum)+thumboffset; }
	
			// take offset into account for thumbnail and bracket display
			ipicnum=picnum-thumboffset;
			// deselect all buttons for old pic and hide old pic 
			eval("document.getElementById('thumb"+ipicnum+"').style.borderColor='#ffffff';");
			eval("document.getElementById('bottomnum"+picnum+"').style.color='#000000';");
			eval("document.getElementById('bottomTD"+picnum+"').style.backgroundColor='#ffffff';");
			eval("document.getElementById('LHbrack_tn"+ipicnum+"').src='"+spacerimage+"';");
			eval("document.getElementById('RHbrack_tn"+ipicnum+"').src='"+spacerimage+"';");
			// generate new picnum
			switch(action) {
				case "prev": picnum--; break;
				case "num": picnum=thepicnum; break;
				case "next": picnum++;
				}
			// hide the 'prev' and 'next' buttons if necessary
			if (picnum==1)   { 
				document.getElementById('prevbutton').style.visibility="hidden"; 
				document.getElementById('nextbutton').style.visibility="visible"; 
				}
			else  {
				document.getElementById('prevbutton').style.visibility="visible"; 
				if (picnum==totpics)   { document.getElementById('nextbutton').style.visibility="hidden";  }
				else  { document.getElementById('nextbutton').style.visibility="visible"; }
				}
	
			// repopulate thumb slideshowimages if new pic number is beyond current scope			
			if (Number(picnum)>thumbfin)   {
				thumbfin=picnum;
				thumbstart=Number(picnum)-4;
				thumboffset=Number(thumbstart)-1;
				for (x=1;x<=totthumbs;x++)   {
					selpic=x+thumboffset-1;
					selimage="thumbimage"+selpic+".src";
					eval("document.getElementById('thumb"+x+"').src="+selimage+";");
					}
				}
			else   {
				if (Number(picnum)<thumbstart)   {
					thumbstart=picnum;
					thumbfin=Number(picnum)+4;
					thumboffset=Number(thumbstart)-1;
					for (x=1;x<=totthumbs;x++)   {
						selpic=x+thumboffset-1;
						selimage="thumbimage"+selpic+".src";
						eval("document.getElementById('thumb"+x+"').src="+selimage+";");
						}
					}
				}
	
			ipicnum=picnum-thumboffset;
			eval("document.getElementById('captiontext').innerHTML=caption"+picnum+";");
			selpic=picnum-1;
			selimage="mainimage"+selpic+".src";
			eval("document.getElementById('mainpic').src="+selimage+";");
			eval("document.getElementById('thumb"+ipicnum+"').style.borderColor='#333333';");
			eval("document.getElementById('LHbrack_tn"+ipicnum+"').src='images/generic/slide-LHbracket.gif';");
			eval("document.getElementById('RHbrack_tn"+ipicnum+"').src='images/generic/slide-RHbracket.gif';");
			eval("document.getElementById('bottomnum"+picnum+"').style.color='#ffffff';");
			eval("document.getElementById('bottomTD"+picnum+"').style.backgroundColor='#990000';");
			}
		}

	function MM_preloadImages() { //v3.0
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
		var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
		if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}} }

