
//the following are updated by init functions such as 'loadthumbs', 'loadimages'
var	tcache = 0;
var	icache = 0;;//set by key input 'f12' to cause renewal and re-display
var imageindex = 0;
var tcount = 0;
var thumbdata = new Array();
var mainarray = "";//name of slide array being used
var thumbloadtimeout = 1000;
var mpathswitch = 0;//global for path vector to be used in path arrays
var startSlidesId = 0;
var SlideRate;//dynamic slide interval
var startorstop = 0;//stopped = 0
var slen = 0;	
var iheight; //dynamic height main picture
var iwidth;//dynamic width
var heightnom ;//transferred from htmlpage java on setup. main picturesize
var widthnom ;//ditto
var theight;//ditto for thumbsize
var twidth;//ditto
var thumbtablewidth = 0;
var thumbcellwidthtotal = 0;
var thumbcellheighttotal;
var thumbtableheight;

var scrollshortside = 21;//for thumbs table
var picturepad = 8; //allowance around picture size for container
var adjh, adjw, strw, strh, ah, aw;
var helpOn = 0;
var helpwidth = 250;
var helpheight = 320;
var helptable;
var helpURL = "";

var thumbcell = "thumb_";//unit name for implanted iframe thumbs
var ithumbdestn = "thumbsxy";//id in iframe page for thumb planting
var thumbdirn;// 0 for horizontal, 1 for vertical thumb placement
var thumbtargetisframe ; //0 for direct thumbs placement, 1 for iframe thumbs placement
var iframethumbID;//thumbframe id 
var horizontal = 0;
var vertical = 1;
var nothumbs=3;

var slidestimer2;
var thumbto = 0;


function setStartConditions(tw, th, pw, ph, sr,  hurl,ps){
	mpathswitch = ps;
	theight = th;
	twidth = tw;//parseInt((theight*4)/3);
	heightnom = ph;
	widthnom = pw;
	iheight = parseInt(ph);
	iwidth = parseInt(pw);
	SlideRate = sr;
	helpURL = hurl;
   	if (document.getElementById("logct")){
		document.getElementById("logct").value = SlideRate+"s";
	}
	setstart();
	setsize();//establishes initial picture size and thumb size
	
}

function getthumbtarget(thumbdestn){
//determine iframe or direct target for thumbs and their direction (horiz, vert)
//setup global vars for other use
	if (!document.getElementById(thumbdestn)){
		thumbdirn = nothumbs;
		return thumbdirn;
	}
		
	//determine if iframe or direct
		if ((thumbdestn.substring(0,1))== "i"){
			thumbtargetisframe= 1;//signals iframe target
			iframethumbID = thumbdestn;//store for later use
			if ((parseInt(document.getElementById(thumbdestn).height))>(parseInt(document.getElementById(thumbdestn).width))){
				thumbdirn = vertical;
			}else{
				thumbdirn = horizontal;
			}
		}else{
			thumbtargetisframe = 0; //signals direct target
	
			if ((thumbdestn.substring(1,2))== "y"){
				thumbdirn = vertical;
			}else{
				thumbdirn = horizontal;
			}				
		}
	return thumbdirn;
}
function loadthumbs (thumbstore, cs, indxname, thumbdestn, tableclass, cellclassnorm){
//thumbstore. The temp image object store to be loaded with image and used for size reading
//cs. The index array value.
//indxname. the array of all array names 
//thumbdestn. The id of the destination for the thumb pictures
//tableclass. the class to be called up for the thumbs table
//cellclassnorm. the class to be called up for the thumbs cells


//alert(twidth+" "+theight);
//determine thumb direction

	if (getthumbtarget(thumbdestn) == nothumbs){
			return false;//return false mean no thumbs reqd so do main pic display immediately
	}

	var slidearray 		= eval(indxname)[cs][4]; //extract main array name
	var thumbpatharray 	= eval(indxname)[cs][2];//ditto thumbs path array name
	
	var i = 0;
//determine occupied length of data array	
        var ilength = eval(slidearray).length//length of array dimension - but it may not be fully loaded so do next check
        for (i = 0; i<ilength; i++){ 
	        findot = eval(slidearray)[i][1].indexOf('.');
	        if (findot <1 ){
		        break;
	        }
        }
	        ilength = i;
//first plant the thumb display containers required for this window

			var interthumbheight = parseInt(theight/8);
			var interthumbwidth = parseInt(twidth/8);

	       if (thumbdirn == horizontal) {	
	       		thumbtableheight = theight+2;//		
	       		thumbcellwidthtotal = twidth+4+interthumbwidth;//(((theight+4)*twidth/theight)+4);        //*4/3)+4);
	       		thumbtablewidth = interthumbwidth + parseInt((thumbcellwidthtotal*ilength));//((parseInt((sh+4)*4/3))+4)*ilength;
      		}else{
	      		thumbcellheighttotal = theight+4+interthumbheight;
	       		thumbtablewidth = twidth+2;
				thumbtableheight = (parseInt((thumbcellheighttotal)*ilength));
			}

	       if (thumbdirn == horizontal) {
	       		var thumbtxt = "<table class =\""+tableclass+"\" width=\""+thumbtablewidth+"\" height=\""+thumbtableheight+"\"  ><tr><td width='"+interthumbwidth+"'></td>";//border=\"1\"
      		}else{//vertical thumbs required
      			var thumbtxt = "<table class =\""+tableclass+"\" width=\""+thumbtablewidth+"\" height=\""+thumbtableheight+"\" align=\"left\" >";//border=\"1\"
  			}

			for (var i = 0; i<ilength; i++){
			var cw = twidth;
			var ch = theight;
			var idthumb = thumbcell + cs+i;
			//note use of 'parent.xxx' in following. this enables similar working with iframe embedded thumbs
	       if (thumbdirn == horizontal) {
	       		thumbtxt = thumbtxt + "<td class = '"+cellclassnorm+"' width='"+cw+"' height='"+ch+"' id = "+idthumb+" onclick='parent.replacemainpic("+i+", "+cs+");return true;'></td ><td width='"+interthumbwidth+"'></td>";
       		}else{
	       		thumbtxt = thumbtxt + "<tr><td class = '"+cellclassnorm+"' width='"+cw+"' height='"+ch+"' id = "+idthumb+" onclick='parent.replacemainpic("+i+", "+cs+");return true;'></td></tr><tr><td height='"+interthumbheight+"'></td></tr>";
       		}
			}
	       if (thumbdirn == horizontal) {
            	thumbtxt = thumbtxt + "</tr></table>";
        	}else{
	        	thumbtxt = thumbtxt + "</table>";
        	}


			if (thumbtargetisframe){	
				if (eval(iframethumbID).document.getElementById(ithumbdestn)){
					eval(iframethumbID).document.getElementById(ithumbdestn).innerHTML = thumbtxt;//plant all accrued thumb table cells
				}
			}else{
				if (document.getElementById(thumbdestn)){
					document.getElementById(thumbdestn).innerHTML = thumbtxt;//plant all accrued thumb table cells
				}
			}
//		alert(thumbtxt)

//display containers ready so start getting data
	var p = 0;
	var ss = "";
	var n = 0;
	tcount = 0;
	var findot;
//the thumb images will be loaded to an image array and displayed from there
 	if (tcache){
	 	eval(thumbstore).length = 0;
	 	tcache = 0;
	}

       //now initiate the right number of image objects in the array
        for (i = 0; i<ilength; i++){ 
            eval(thumbstore)[i] = new Image();
//            eval(thumbstore)[i].src = undefined;//clear previous cache in case picture res changed during development. (but title same)
        }
       
        // set function to catch when last image is loaded so display can be triggered.

//	     eval(thumbstore)[ilength-1].onload = function (){displaythumbs(thumbstore, cs, indxname, thumbdestn, tableclass, cellclassnorm,ilength);}
	thumbdata[0] = thumbstore;
	thumbdata[1] = cs;
	thumbdata[2] = indxname;
	thumbdata[3] = thumbdestn;
	thumbdata[4] = tableclass;
	thumbdata[5] = cellclassnorm;
	thumbdata[6] = ilength;
	//the above array required because the setTimeout function (later) cannot carry all the parameters
	
 	for (var n = 0; n< ilength; n++){
	 	 eval(thumbstore)[n].onload = function (){ thumbsaccrue();}//thumbstore, cs, indxname, thumbdestn, tableclass, cellclassnorm,ilength);}
 	 }  
    //continuation of thumbs loading to cache function
    for (i = 0; i<ilength; i++){ 
				//convert extensions to jpg for thumbs files
				findot = eval(slidearray)[i][1].indexOf('.');

				if (findot>1){
					var thumbfile = eval(slidearray)[i][1].substring(0,findot)+".jpg";
					var p = parseInt(eval(slidearray)[i][0]);//get path to pics
					var thb = eval(thumbpatharray)[p]+thumbfile;
           			eval(thumbstore)[i].src = thb;
       			}
 	}
 	
//	displaythumbs(thumbstore, cs, indxname, thumbdestn, tableclass, cellclassnorm,ilength); 
	
	
return true;//return false mean no thumbs reqd so do main pic display immediately
}

function thumbsaccrue(){//thumbs loaded event response
	tcount++;
	clearTimeout(thumbto);

	if (tcount == thumbdata[6]){//thumbs are only loaded to display when all are loaded to cache.
		displaythumbs(thumbdata[0], thumbdata[1], thumbdata[2], thumbdata[3], thumbdata[4], thumbdata[5], thumbdata[6]);
	}
	else{
		thumbto = setTimeout("thumbsfollow()",thumbloadtimeout);//run timeout per thumbload
	}
}
function thumbsfollow(){
	tcount = thumbdata[6]+1;
	displaythumbs(thumbdata[0], thumbdata[1], thumbdata[2], thumbdata[3], thumbdata[4], thumbdata[5], thumbdata[6]);
}

//called on each thumb load event. checks when all complete and performs display function
function displaythumbs(thumbstore, cs, indxname, thumbdestn, tableclass, cellclassnorm,ilength){

		var slidearray 		= eval(indxname)[cs][4]; //extract main array name
		var thumbpatharray 	= eval(indxname)[cs][2];//ditto thumbs path array name

	//cells made so now fill  with the thumb images
			var xx= "";	
			var p = "";
			var thumbfile = "";
			var thb = "";
			var strw = 0;	
			var strh = 0;
			var ah = 0;
			var aw = 0;
			for (var i = 0; i<ilength; i++){
				xx = thumbcell+cs+i;

				if (thumbtargetisframe){//an iframe is present so load the iframe child page rather than the parent

					if (eval(iframethumbID).document.getElementById(xx)){

				//convert extensions to jpg for thumbs files
					findot = eval(slidearray)[i][1].indexOf('.');
					thumbfile = eval(slidearray)[i][1].substring(0,findot)+".jpg";

					if (eval(thumbstore)[i].src){
						thb = eval(thumbstore)[i].src;//get filename inc. path from cache
					}else{
						p = parseInt(eval(slidearray)[i][0]);//get path to pics
						thb = eval(thumbpatharray)[p]+thumbfile;
					}

					strw = eval(thumbstore)[i].width;
            		strh = eval(thumbstore)[i].height;
            	//try height fit first then if resulting width too much, do width fit first.
					ah = theight;
					aw = strw * ah / strh
           			if (aw >= twidth){
                		aw = theight * twidth/theight;//4/3;
                		ah = aw * strh / strw;
            		}
            		//having determined size, plant the image in the cell. plant in child page in iframe

					eval(iframethumbID).document.getElementById(xx).innerHTML	=	"<img src='"+thb+"' width='"+aw+"' height='"+ah+"' >";
					}

				}
				
				else{//thumbs not in iframe so deal with directly
					if (document.getElementById(xx)){
				//convert extensions to jpg for thumbs files
					findot = eval(slidearray)[i][1].indexOf('.');
					thumbfile = eval(slidearray)[i][1].substring(0,findot)+".jpg";
					p = parseInt(eval(slidearray)[i][0]);//get path to pics
					thb = eval(thumbpatharray)[p]+thumbfile;

					strw = eval(thumbstore)[i].width;
            		strh = eval(thumbstore)[i].height;
            	//try height fit first then if resulting width too much, do width fit first.
					ah = theight;
					aw = strw * ah / strh
           			if (aw >= twidth){
                		aw = theight * twidth/theight;   //4/3;
                		ah = aw * strh / strw;
            		}
            		//having determined size, plant the image in the cell.

					document.getElementById(xx).innerHTML	=	"<img src='"+thb+"' width='"+aw+"' height='"+ah+"' >";
					}					

				}
			//note that selected cell highlighting is a separate function
			}
			
			followthumbsload(cs);//image set trigger load of main pics. this done after thumbs to ensure iframe gets correct dimensions when triggered
}//end of thumbs loaded to html page function after event trigger


function loadimages (slidestore, firstimage, cs, indxname){
//slidestore. The temp image object store to be loaded with image and used for size reading
//firstimage. the first image to be displayed.
//cs. The first dimension of the source array to be used.
//indxname. the array of all array names 

		var slidearray 		= eval(indxname)[cs][4]; //extract main array name
		var slidepatharray 	= eval(indxname)[cs][3];//ditto slides path array name

		mainarray = slidearray; //ditto	
       var p = 0;
       var ss = "";
       var i = 0; 

//initialise the image array
        if (icache){
	        eval(slidestore).length = 0;
	        icache = 0;
        }
        var ilength = eval(slidearray).length//length of array dimension - but it may not be fully populated so do next check

        for (i = 0; i<ilength; i++){ 
	        findot = eval(slidearray)[i][1].indexOf('.');
	        if (findot <1 ){
		        break;
	        }
        }
	        ilength = i;
        for (i = 0; i<ilength; i++){ 

           eval(slidestore)[i] = new Image();
//            eval(slidestore)[i].src = undefined;//clear previous cache in case picture res changed during development. (but title same)
        }

// set function to catch when first image is loaded so initial display can be triggered.

     eval(slidestore)[firstimage].onload = function(){//IMPORTANT NOTE  this onload function must be initiated before the loading process else it might be bypassed. onload only produces a trigger at the instant of loading conclusion. If it has already done it then no trigger will be produced.

         replacemainpic(firstimage, cs);//must run in main page javascript to pick up associated functions.
     }
    for (i = 0; i<ilength; i++){ 
        var p = parseInt(eval(slidearray)[i][0]);// get path to pics

        var	ss =eval(slidepatharray)[mpathswitch][p] + eval(slidearray)[i][1];//get pic filename

        var dot = ss.indexOf('.');//check if there is an filename present. only upload if there is
        if (dot > 1){
        	var tt =  ss.substring(dot+1,dot+4);
        	if (tt!="htm"){
           		eval(slidestore)[i].src = ss;
				}
       		}
   		}
    }




//------------

function highlightThumb(newpic, cs,indxname, thumbdestn, cellclasslit, cellclassnorm){//hightlight the thumb of the selected image

//first adjust scrollbar if there is one:
	//set iframe for thumbs to same width or height if it exists
		if (getthumbtarget(thumbdestn)==nothumbs){
			return;
		}	
		if (thumbtargetisframe){
			if (thumbdirn == horizontal){
				document.getElementById(iframethumbID).width = adjw;
				document.getElementById(iframethumbID).height = thumbtableheight+scrollshortside;

			}else{//thumbs else vertical
				document.getElementById(iframethumbID).height = adjh;
				document.getElementById(iframethumbID).width = thumbtablewidth+scrollshortside;
//alert(thumbtablewidth+scrollshortside);
			}
		}
		
		var xx = "";
		var slidearray 		= eval(indxname)[cs][4]; //extract main array name	
//		getthumbtarget(thumbdestn);		
        var ilength = eval(slidearray).length//length of array dimension - but it may not be fully loaded so do next check
        for (i = 0; i<ilength; i++){ 
	        findot = eval(slidearray)[i][1].indexOf('.');
	        if (findot <1 ){
		        break;
	        }
        }

	        ilength = i;
		if (thumbtargetisframe){//case of thumbs embedded in iframe
			//first restore all table cells to not highlighted
			for (var n = 0; n<ilength;n++){
				xx = thumbcell+ cs +n;
				if (eval(iframethumbID).document.getElementById(xx)){
					eval(iframethumbID).document.getElementById(xx).className = cellclassnorm;
				}
			}

			//then highlight the selected cell			
			xx = thumbcell+ cs +newpic;
			if (eval(iframethumbID).document.getElementById(xx)){
				eval(iframethumbID).document.getElementById(xx).className = cellclasslit;
			}
			//now put the highlighted thumb in the middle of the scrolled iframe
	       //newpic/slen * thumbtablewidth = pixels to reach newpic
		if (thumbdirn == horizontal){
	       var ipos = parseInt((newpic/slen)* thumbtablewidth);
	       

	       if (ipos < iwidth*0.5){
		       ipos = 0;
	       }else{
		       ipos = ipos-(iwidth/2);
	       }
			window.eval(iframethumbID).scrollTo(ipos,0);		//set the scrollbar position to put the selected pic in the middle	
		}else{
	       var ipos = parseInt((newpic/slen)* thumbtableheight);
	       if (ipos < iheight*0.5){
		       ipos = 0;
	       }else{
		       ipos = ipos-(iheight/2);
	       }
			window.eval(iframethumbID).scrollTo(0,ipos);
		}
			
		}else{//for case of thumbs not embedded in iframe
			//first restore all table cells to not highlighted
			for (var n = 0; n<ilength;n++){
				xx = thumbcell+ cs + n;
				if (document.getElementById(xx)){
					document.getElementById(xx).className = cellclassnorm;
				}
			}
			//then highlight the selected cell			
			xx = thumbcell+ cs + newpic;
			if (document.getElementById(xx)){
				document.getElementById(xx).className = cellclasslit;
			}
		}	
}


function getadjwh(){
		adjh = iheight+picturepad;
		adjw = iwidth+picturepad;
}

function setsize(){
		getadjwh();

		if (document.getElementById('heightadjuster')){
			document.getElementById('heightadjuster').innerHTML = "<img src='graphics/1t10pix.gif' width='1' height='"+adjh+"'>"; 
	} 
		if (document.getElementById('widthadjuster')){
			document.getElementById('widthadjuster').innerHTML = "<img src='graphics/1t10pix.gif' width='"+adjw+"' height='1'>"; 

	}

}
		
function replacepic(newpic, cs, indxname, slidestore,  sdestn, thumbdestn, cellclasslit, cellclassnorm){
//newpic. the picture index in the chosen dimension of the array.
//cs. The first dimension of the source array to be used.
//indxname. the array of all array names 
//slidestore. The temp image object store to be loaded with image and used for size reading
//sdestn. The id of the destination for the slide pictures

		var slidearray 		= eval(indxname)[cs][4]; //extract main array name
		var slidepatharray 	= eval(indxname)[cs][3];//ditto slides path array name

		imageindex = newpic;//for use by other functions as a global	
		getadjwh();
		highlightThumb(newpic, cs,indxname, thumbdestn, cellclasslit, cellclassnorm);

		var p,ss;
		if (eval(slidestore)[newpic].src){
			ss = eval(slidestore)[newpic].src;//get filename inc. path from cache

		}else{//get it from source
			var p = parseInt(eval(slidearray)[newpic][0]);//get path to pics
			var ss = eval(slidepatharray)[mpathswitch][p]+eval(slidearray)[newpic][1];//get filename inc. path
		}

				slen = eval(slidearray).length;
		if(document.getElementById("slcnt")){
			document.getElementById("slcnt").value = newpic + 1 + "/" + slen;//plant slideno/total slides for slideshow
		}
		
		var dot = ss.indexOf('.');
		var tt =  ss.substring(dot+1,dot+4);

//alert(ss)
//note that the iframe is only needed for movie.

		if (tt=="htm"){
//		alert("movie");
			if (document.getElementById('TopFrame')){
		 	  document.getElementById('TopFrame').src="dummy.html";
			  pausecomp(400);
			  document.getElementById('TopFrame').style.display="none";
			  pausecomp(400);
			   }
			stopSlides();//halt slideshow if movie to be shown
		   document.getElementById(sdestn).innerHTML="<iframe id='TopFrame' name='TopFrame' frameborder='0' src='' width='"+iwidth+"' height='"+iheight+"'onclick='jumpback()'>Your browser does not support iframes.</iframe>";
		   pausecomp(400);
		document.getElementById('TopFrame').src=ss//"keyhelp.html";//ss;
		
		 }
		 else{
//alert("still");

		if (document.getElementById('TopFrame')){
			 	  document.getElementById('TopFrame').src="dummy.html";
				  pausecomp(400);
				  document.getElementById('TopFrame').style.display="none";
				  pausecomp(400);
			}

			

//determine correct image display size from original aspect and size. 
            strw = eval(slidestore)[newpic].width;
            strh = eval(slidestore)[newpic].height;
            //try height fit first then if resulting width too much, do width fit first.
			ah = iheight;
			aw = parseInt(strw * ah / strh)
           if (aw >= iwidth){
                aw = parseInt(iheight *  widthnom/heightnom);//  4/3);
                ah = parseInt(aw * strh / strw);
            }
			if (helpOn){
	        	helptable = "<iframe id=\"hframe\" name=\"hframe\" frameborder='1' src='' width='"+helpwidth+"' height='"+helpheight+"' style=\"display:inline;\" align='left'></iframe>&nbsp;";
				if ((iwidth-(helpwidth+6))< aw){
					
					// aw = aw- (aw-(iwidth-(helpwidth+6)))//(helpwidth+6);
					 aw = iwidth-(helpwidth+6);
				 }
					 
			}else{
				helptable = "";
			}
			
            	if (document.getElementById(sdestn)){
	            	document.getElementById(sdestn).innerHTML = helptable+"<img id = 'mainpic' name = 'mainpic' class='imgp' style=\"display:inline;\" src='"+ss+"' width='"+aw+"' height='"+ah+"' >";
				
            	}		
            	else{alert("element "+sdestn+" is missing in html")
            	}
            	if(document.getElementById("hframe")){
	            	document.getElementById("hframe").src=helpURL;
            	}
               
		}	
}
//---------------------------------
//replacetxt plants the correct text in the designated containers for the current slide

function replacetxt(newpic, cs, indxname, gtxtdestn, dtxtdestn){
//newpic. the picture index
//cs. The first dimension of the source array to be used.
//indxname. the array of all array names 
//gtxtdestn. the destination of the group text
//dtxtdestn. the destination of the detail text
		var slidearray 		= eval(indxname)[cs][4]; //extract main array name
		var gtxtarray 	= eval(indxname)[cs][1];//ditto grouptext array name
	
		var dd = eval(slidearray)[newpic][3];//get pic text details
		var p = eval(slidearray)[newpic][2];//get index to group text
		var gt = eval(gtxtarray)[p];//get actual group text
		if (document.getElementById(dtxtdestn)){
			document.getElementById(dtxtdestn).innerHTML=dd;//plant slide description
		}
		if (document.getElementById(gtxtdestn)){
			document.getElementById(gtxtdestn).innerHTML=gt;//plant group text
		}
}
//---------------------------------

function replacetitle(cs, indxname, tdestn){
//cs. The first dimension of the source array to be used.
//indxname. name of primary index array which identifies all other array names
//tdestn. destination id for title
		var titlearray 		= eval(indxname)[cs][0]; //extract title text array name
	try {
		document.getElementById(tdestn).innerHTML= eval(titlearray)[0];
	}
	catch(err){};		
}


//-------------------------------

function 	incdecimage(x){//put next slide on from key input
		cancelfade();
		incdecimagex(x);
}
function incdecimagex(d){

	var n = 0;
	var alength = eval(mainarray).length

	switch (d){
		case 1:
			imageindex++;
        	for (n = imageindex; n<alength;n++){
				var dot = eval(mainarray)[n][1].indexOf('.');//check if there is an filename present. only upload if there is
  		      	if (dot > 1){
					break;
				}
       		}
       		imageindex = n;
			if (imageindex >= alength){
			imageindex = 0;
			}

			break;
		default:
			imageindex--;
			if (imageindex <0 ){
			imageindex = alength-1;
			}
        	for (n = imageindex; n>0;n--){
				var dot = eval(mainarray)[n][1].indexOf('.');//check if there is an filename present. only upload if there is
  		      	if (dot > 1){
					break;
				}
       		}
       		imageindex = n;
			break;
		}

		replaceimg(imageindex);
}
//---------------------------
function pausecomp(millis) 
{
var date = new Date();
var curDate = null;

do { curDate = new Date(); } 
while(curDate-date < millis);
} 
//----------------------------

function restoresize(){//restore default size
	if (document.getElementById('TopFrame')){
		return;//abort if movie running.
	}
	iheight = parseInt(heightnom);
	iwidth = parseInt(widthnom);
	setsize();
	replaceimg(imageindex);
}	

function intUp2(){//increase image size
	if (document.getElementById('TopFrame')){
		return;//abort if movie running.
	}
	iheight = parseInt(iheight * 1.025);
	if (iheight > (2* heightnom)){
		iheight = parseInt(2* heightnom);
	}
	iwidth = (parseInt((iheight*widthnom)/heightnom));//    4)/3));
	setsize();
	replaceimg(imageindex);
}

function intDn2(){//decrease image size
	if (document.getElementById('TopFrame')){
		return;//abort if movie running.
	}
	iheight = parseInt(iheight * 0.975);
	if (iheight < (0.5*heightnom)){
		iheight = parseInt(0.5*heightnom);
	}
	iwidth = (parseInt((iheight*widthnom)/heightnom));//    4)/3));	
	setsize();
	replaceimg(imageindex);
}

//--------------------




function setstart(){//initialise variables and start conditions

	if (document.getElementById("startstop")){
		document.getElementById("startstop").innerHTML = "<a href=\"#\" onclick=\"javascript:return startSlides();\"onMouseOut=\"document.startplay.src=\'graphics/startplay.gif\' \" onMouseOver=\"document.startplay.src = \'graphics/startplay-h.gif\'\"><img src=\"graphics/startplay.gif\" name=\"startplay\" id = \"startplay\" width=\"30\" height=\"19\" alt=\"\" border=\"0\"></a>";
	}
	if (document.getElementById("runcon")){
		document.getElementById("runcon").src='graphics/4r1-still.gif'
		document.getElementById("runcon").className = "a0";
		}	
	
}
function setstop(){

	if (document.getElementById("startstop")){
		document.getElementById("startstop").innerHTML = "<a href=\"#\" onclick=\"javascript:return stopSlides();\"onMouseOut=\"document.stopplay.src=\'graphics/stopplay.gif\' \" onMouseOver=\"document.stopplay.src = \'graphics/stopplay-h.gif\'\"><img src=\"graphics/stopplay.gif\" name=\"stopplay\" id = \"stopplay\" width=\"30\" height=\"19\" alt=\"\" border=\"0\"></a>";
	}
	if (document.getElementById("runcon")){
		document.getElementById("runcon").src='graphics/4r1-mov.gif'
		document.getElementById("runcon").className = "a2";
		}//
	}
function startSlidesUp(){
	if (startorstop == 0 ){
		startSlides()
	}
	else{
		stopSlides()
	}
}

function startSlides (){
	if (document.getElementById('TopFrame')){
		return;//abort if movie running.
	}
  	setstop();
  	startorstop = 1; 
    startSlidesId = setInterval ( "nextslide()", SlideRate*1000 );
}
function stopSlides(){
   setstart();
   startorstop = 0;
    clearInterval ( startSlidesId );
    cancelfade();
}


function intDn(){//decrease slide interval
	if (document.getElementById('TopFrame')){
		return;//abort if movie running.
	}	
	SlideRate--;
	if (SlideRate > 10){
	SlideRate--;
	}
	if (SlideRate > 20){
	SlideRate=SlideRate-2
	}
	if (SlideRate <=1){
		SlideRate = 1;
	}
	if (document.getElementById("logct")){
		document.getElementById("logct").value = SlideRate+"s";
	}

  if ( startorstop == 1){// (means slide show is running so stop it first)
  	 clearInterval ( startSlidesId );//stop slideshow, wait, then start slideshow
	 cancelfade();
	 pausecomp(250);
  	 startSlidesId = setInterval ( "nextslide()", SlideRate*1000 )
	 }
}	
//----------
function intUp(){//increase slide interval

	if (document.getElementById('TopFrame')){
		return;//abort if movie running.
	}
	SlideRate++;
	if (SlideRate > 10){
	SlideRate++;
	}
	if (SlideRate > 20){
	SlideRate=SlideRate+2;
	}
	if (SlideRate >=60){
		SlideRate = 60;
	}
	if (document.getElementById("logct")){
		document.getElementById("logct").value = SlideRate+"s";
	}

  if ( startorstop == 1){// means slide show is running
	 clearInterval ( startSlidesId );//stop slideshow, wait, then start slideshow
	 cancelfade();
	 pausecomp(250);
	 startSlidesId = setInterval ( "nextslide()", SlideRate*1000 )
	 }
}

//------------------
function fadeonoff(){
	if (document.getElementById("fadeon")){
		if(document.getElementById("fadeon").checked){
			document.getElementById("fadeon").checked = false;
			cancelfade();
		}else{
			(document.getElementById("fadeon").checked) = true;
		}
	}
}	


//slide transition achieved as:
//- fadeout current slide
//- wait 100ms
//- fade in new slide

function nextslide(){
	cancelfade();
	if ((document.getElementById("fadeon"))&&(document.getElementById("fadeon").checked)){
		fadeout("Picture0");//initiates aftertime() when complete
		}else{
			incdecimagex(1);//put next slide on
		}
}

function aftertime(){
	clearTimeout(slidestimer2);
	fadein("Picture0");//start fadein on cell holding image (not picture, else brief full image can appear)
	incdecimagex(1);//put next slide on
}

function cancelfade(){
	 clearInterval(slidestimer);//stop slide fade timer
	instantopac("Picture0", 100);//make fully visible
}	
//-------------------------
	


var ttime;
var opac;
var slidestimer;
var speed;

var imgobjectin;
var imgobjectout;

function fadein(id) {
		imgobjectin = document.getElementById(id).style; 
    	speed = 15;// interval ms
		ttime = 0;
	    slidestimer = setInterval("fadeinstep('"+id+"',3)",speed);
}
function fadeout(id){
		imgobjectout = document.getElementById(id).style;
    	speed = 15;//interval ms
		ttime = 0;
	    slidestimer = setInterval("fadeoutstep('"+id+"',20)",speed);
}	

//step up the opacity for different browsers 
function fadeinstep(id, stepval) { 
	opac = ttime*stepval;
	if (opac >100){
		opac = 100;
	}
	ttime++;
//    var imgobjectin = document.getElementById(id).style; 
    imgobjectin.opacity = (opac / 100); 
    imgobjectin.MozOpacity = (opac / 100); 
    imgobjectin.KhtmlOpacity = (opac / 100); 
    imgobjectin.filter = "alpha(opacity=" + opac + ")";
     
 	if (opac >=100){
	 	opac = 100;
	 	ttime = 0;
		clearInterval(slidestimer);
	}   
} 

//step down the opacity for different browsers 
function fadeoutstep(id, stepval) { 
	opac = 100-(ttime*stepval);
	if (opac <0 ){
		opac = 0;
	}
	ttime++;
//    var imgobjectout = document.getElementById(id).style; 
    imgobjectout.opacity = (opac / 100); 
    imgobjectout.MozOpacity = (opac / 100); 
    imgobjectout.KhtmlOpacity = (opac / 100); 
    imgobjectout.filter = "alpha(opacity=" + opac + ")";
     
 	if (opac == 0){
	 	ttime = 0;
		clearInterval(slidestimer);
		slidestimer2 = setTimeout("aftertime()",100);//triggers next step after 100ms
	}   
} 
//change the opacity for different browsers 
function instantopac(id, opac){
    var imgobject = document.getElementById(id).style; 
    imgobject.opacity = (opac / 100); 
    imgobject.MozOpacity = (opac / 100); 
    imgobject.KhtmlOpacity = (opac / 100); 
    imgobject.filter = "alpha(opacity=" + opac + ")";
}

//change the opacity for different browsers 
function changeOpac(opacity, id) { 
    imgobject = document.getElementById(id).style; 
    imgobject.opacity = (opacity / 100); 
    imgobject.MozOpacity = (opacity / 100); 
    imgobject.KhtmlOpacity = (opacity / 100); 
    imgobject.filter = "alpha(opacity=" + opacity + ")"; 
} 
 

function helpframepage(){
	if (helpOn){
		helpOn = 0;//turn it off
	}else{
		helpOn = 1;//turn it on
	}
	replaceimg(imageindex);
}
