/*	Image rotator for home page */

	ARRxImages   = new Array();
	ARRxCaptions = new Array();
	ARRxLinks    = new Array();

	ARRxImages[0]   ='centre.jpg';
	ARRxCaptions[0] ='BCHRC building';
	ARRxLinks[0]    ='aboutus.asp';
		
	ARRxImages[1]   ='volunteers.jpg';
	ARRxCaptions[1] ='BCHRC volunteers';
	ARRxLinks[1]    ='volunteering.asp';
	
	ARRxImages[2]   ='racking.jpg';
	ARRxCaptions[2] ='Museum standard storage';
	ARRxLinks[2]    ='storing-items.asp';
	
	ARRxImages[3]   ='hocmuseum.jpg';
	ARRxCaptions[3] ='The House on Crutches';
	ARRxLinks[3]    ='hoc/';
	
	ARRxImages[4]   ='househistorygroup.jpg';
	ARRxCaptions[4] ='BCHRC researchers';
	ARRxLinks[4]    ='index.asp';
	
	ARRxImages[5]   ='shoes.jpg';
	ARRxCaptions[5] ='Shoes from the House on Crutches Museum collection';
	ARRxLinks[5]    ='hoc/collection/';
	
	ARRxImages[6]   ='tannery.jpg';
	ARRxCaptions[6] ='From the photo collection';
	ARRxLinks[6]    ='index.asp';

	ARRxImages[7]   ='cards.jpg';
	ARRxCaptions[7] ='Playing cards from the House on Crutches Museum collection';
	ARRxLinks[7]    ='hoc/collection/';

	ARRxImages[8]   ='cashbook.jpg';
	ARRxCaptions[8] ='Cashbook from the House on Crutches Museum collection';
	ARRxLinks[8]    ='hoc/collection/';

	rotateNum = 0;
	xRandom   = 0;
	
/*	------------------------------------------------------------------------------ */

	function setRandomImage(xDiv) {

		xDiv  = document.getElementById(xDiv);
		xLink = document.getElementById('imglink');

		maxImages = ARRxImages.length - 1;

		pRandom = xRandom;

		// Random order option...
		//xRandom = Math.floor(Math.random() * maxImages);
		//if (xRandom >= maxImages) {xRandom = maxImages};

		// Sequential order option...
		xRandom = rotateNum;
		rotateNum += 1;
		if (rotateNum > maxImages) rotateNum = 0;
		
		xImageSrc     = 'images/rotator/' + ARRxImages[xRandom];
		xImageCaption = ARRxCaptions[xRandom];
		xImageLink    = ARRxLinks[xRandom];
		
		xImageHTML =  '<img';
		xImageHTML += ' src="' + xImageSrc + '"';
		xImageHTML += ' width="350"';
		xImageHTML += ' height="250"';
		xImageHTML += ' border="0"';
		xImageHTML += ' alt="' + xImageCaption + '"';
		xImageHTML += ' /></a>';

		xDiv.innerHTML = xImageHTML;
		xLink.href  = ARRxLinks[pRandom];
		xLink.title = ARRxCaptions[pRandom];
	}

/*	------------------------------------------------------------------------------ */

	function setOpacity(xDiv, xOpac) {
		xDiv = document.getElementById(xDiv);
		xDiv.style.opacity = (xOpac/100);
		xDiv.style.MozOpacity = (xOpac/100);
		xDiv.style.KhtmlOpacity = (xOpac/100);
		xDiv.style.filter = 'alpha(opacity=' + xOpac + ')';
		document.getElementById('xopacdiv').value = xOpac;
	}

/*	------------------------------------------------------------------------------ */

	function SwapImages() {
		ximgdiv1 = document.getElementById('imgdiv1')
		ximgdiv2 = document.getElementById('imgdiv2')
		if (document.getElementById('xopacdiv').value==100) {
			setTimeout("setRandomImage(\"imgdiv2\")", 1000);
			for (o=0;o<=100;o++) {
				ot=o*10;
				op=100-(o);
				setTimeout('setOpacity(\'imgdiv2\', ' + op + ')', ot);
			}
		} else {
			setTimeout('setRandomImage(\'imgdiv1\')', 1000);
			for (o=0; o<=100; o++) {
				ot = o*10;
				op = o;
				setTimeout('setOpacity(\'imgdiv2\', ' + op + ')', ot);
			}
		}
	}

/*	------------------------------------------------------------------------------ */

	window.onload = function() {
		setRandomImage('imgdiv2');
		setRandomImage('imgdiv1');
		setOpacity('imgdiv2', 100);
		setOpacity('imgdiv1', 100);
		setInterval('SwapImages()', 5000);
	}


