//Functions  -
//	function change_display( disparray )	- controls changes the picture array & display
//	function nl_unload_recArray()			- clears the current display array values -  recArray
//	function nl_loadRecArray(selArray)		- Loads the selected array into the display array
//	function nl_displayNextPic(increment)	- Loads the selected pic into the display image	

//	Inputs - a text string that represents the name of the array is passed to change_display(). 
//		the word "Array" is concatenated to this to give the actual array name.
//		eg "Gate" + "Array" = "GateArray" in the *.js file that has the array details eg. picArrays.js file

var currentrec = 0;
var recArray = new Array();
var loop = 0;

function change_display( disparray, dispPics, nameImage )		// Change Picture control function, receives the new array to load
{
//alert ("Change Display : " + disparray + "     recArray: " + recArray);
nl_unload_recArray();						// Empty the recArray
//alert ("B4 reload : " + disparray + " recArray: " + recArray);

var tmp_name=eval(disparray + "Array");				// Add the Array suffix to the passed value
nl_loadRecArray(tmp_name);					// Reload the recArray with the selected array
//alert ("B4 jump : " + disparray + " recArray: " + recArray);

//mainjump("+1*main");						// load the main form with the first record
nl_displayNextPic(1, dispPics, nameImage)
//alert ("B4 at end : " + disparray + " recArray: " + recArray);

}

function nl_unload_recArray()					// clear the existing recArray values
{
//alert("Empty record array: " + " loop:" + loop + " recLength: " + recArray.length + " array record: " + recArray[loop]);
recArray.splice(0,recArray.length);
}

function nl_loadRecArray(selArray)					// Loads the selected array into the display array	
{
//alert("BEGIN nl_loadRecArray: " + selArray + "  :  " + selArray.length + "  :  " + recArray.length);
// load new values into recArray
for (loop=1; loop <= selArray.length - 1; loop++)
 {
   recArray[loop] = selArray[loop];
   //alert("LOOP nl_loadRecArray: " + " loop:" + loop + " sel array value: " + selArray[loop] + " rec array value: " + recArray[loop] + " records: " + selArray.length + "  " + recArray.length);
 }
//alert("END nl_loadRecArray  selArray: " + selArray + "  selArray length:  " + selArray.length + " recArray:  " + recArray.length);
currentrec = 0;						// the first call will increment this by one.
}

function nl_displayNextPic(increment, noPics, namePics)				// Loads the selected pic into the display image	
{
//alert("nl_displayNextPic.   "  + "   currentrec:" + currentrec + "   recArray.length: " + recArray.length + "   recArray: " + recArray);

// we have the increment (forwards/backwards) in increment
currentrec = eval(currentrec + increment);
//alert("Before If test: " + currentrec + " : " + recArray.length);
if (currentrec < 1) {
  //alert("Loop to rear : " + currentrec + "  " + recArray.length);
  currentrec = recArray.length - 1; }							// Loop to end of list
else if (currentrec >= recArray.length) {
  //alert("Loop to Start : " + currentrec + "  " + recArray.length);
  currentrec = 1 }									// Loop to start of list
else {
  //alert("leave as is : " + currentrec + "   " + recArray.length + "    " + recArray);
  																//Do nothing
};

// recode - handles the shuffle regardless of how many pics are on the page
reLoop=1;
var theImageName='';
for (loop=1; loop <= noPics; loop++)
{
  if ( currentrec + (loop) > recArray.length ) {	//implicit assumption that the # of pics > # of displayed pics
    theImageName=namePics + loop;
	var tmpH=document.getElementById(theImageName);
    tmpH.src=recArray[reLoop];
	reLoop++
  }
  else {
    theImageName=namePics + loop;
	var tmpH=document.getElementById(theImageName);
    tmpH.src=recArray[currentrec + (loop-1)];
  }
}

}

//alert("switchpics.js : ");