// Special thanks to Triche Osborne for help with this javascript
// Preload images:
if (document.images) 
{

	//Initialize image arrays:

	var webArray = new Array();
	var printArray = new Array();

	function preloadImages()
	{
		/* Initialize images and define their sources using preload template: 

		var IMAGEArray[#] = new Image();
		IMAGEArray[#].src = "./images/IMAGE#.gif"

		*/

		for (var count = 1; count <= 30; count++)
		{
			webArray[count] = new Image();
			webArray[count].src = "./images/web" + count + ".gif";
		}

		for (count = 1; count <= 7; count++)
		{
			printArray[count] = new Image();
			printArray[count].src = "./images/print" + count + ".gif";
		}
	}
}

//Slideshow section:

	var webCurrent = 1;
	var printCurrent = 1;
	var random = -1;
	var tempArray = new Array();
	var newCurrent;

if (document.images) 
{

	function evalImageSource(current,type)
	{
		return "./images/" + type + current + ".gif";
	}

	function fillTempArray(tempArray, length)
	{
		var boundary = length - 1;
		for (var count = 0; count < boundary; count++)
		{
			tempArray[count] = count + 1;
		}
		return tempArray;
	}	

	function rotate(type,direction) 
	{
		var webArrayLength = webArray.length;
		var printArrayLength = printArray.length;
		var thisCurrent = eval(type + "Current");
		var thisArrayLength = eval(type + "ArrayLength");

		if (direction == "back") 
		{
			newCurrent = (thisCurrent == 1) ? thisArrayLength - 1 : thisCurrent - 1;
		}

		else if (direction == "forward") 
		{
			newCurrent = (thisCurrent == thisArrayLength -1) ? 1 : thisCurrent + 1;
		}

		else //random
		{
	
			if (random == -1)
			{
				fillTempArray(tempArray, webArrayLength);
				tempArray.splice(0, 1);

			} else
			{
				tempArray.splice(random, 1);
			}

			if (tempArray.length == 0)
			{
				fillTempArray(tempArray, webArrayLength);
			}
		
			random = Math.round(Math.random() * (tempArray.length - 1));
			newCurrent = tempArray[random];

		}
		var newImageSource = evalImageSource(newCurrent,type);
		document.images[type].src = newImageSource;
		if (type == 'web')
		{
			webCurrent = newCurrent;
		} else
		{
			printCurrent = newCurrent;
		}
	}

	function popUp(type)
	{
		var look="toolbar=0,statusbar=0,menubar=0,width=550";
		var thisPageNumber = eval(type + "Current");
		var popSource = "./popups/" + type + thisPageNumber + ".html";
		var popWin=window.open(popSource,"pageWindow",look);
		popWin.focus();
	}
}
