			
//<script>

var grid = {x:9, y:10};
var imgDisplaySrc = ['', 'mhl.jpg',
						'1866_4202_091124.jpg',
						'1230_1101_011108.jpg',
						'1430_1500_030411A.jpg',
						'1591_1311_091124.jpg',
						'1634_1301_050623.jpg',
						'1676_1500_060904.jpg',
						'1684_5315_060308.jpg',
						'1685_1430_060223.jpg',
						'1810_8000_070731.jpg',
						'1849_4105_080305.jpg',
						'1866_1300_090817.jpg',
						'1874_1300_080425.jpg',
						'1885_7101_081024.jpg',
						'1921_7805_080925.jpg',
						'1965_0855_090309.jpg'
					];

var wipes = [
			{
				name: 'random',
				timing: 10,
				wipe: []
			},{
				name: 'iris',
				timing: 50,
				wipe: [
					[32],
					[31, 33],
					[30, 34, 19, 45],
					[29, 35, 18, 20, 44, 46],
					[28, 36, 17, 21, 6, 43, 47, 58],
					[27, 37, 16, 22, 5, 7, 42, 48, 57, 59],
					[26, 38, 15, 23, 4, 8, 41, 49, 56, 60],
					[14, 24, 3, 9, 40, 50, 55, 61],
					[13, 25, 2, 10, 39, 51, 54, 62],
					[1, 11, 53, 63],
					[0, 12, 52, 64]
				]
			},{
				name: 'rows',
				timing: 100,
				wipe: [
					[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
					[13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25],
					[26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38],
					[39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51],
					[52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64]
				]
			},{
				name: 'columns',
				timing: 100,
				wipe: [
					[0, 13, 26, 39, 52],
					[1, 14, 27, 40, 53],
					[2, 15, 28, 41, 54],
					[3, 16, 29, 42, 55],
					[4, 17, 30, 43, 56],
					[5, 18, 31, 44, 57],
					[6, 19, 32, 45, 58],
					[7, 20, 33, 46, 59],
					[8, 21, 34, 47, 60],
					[9, 22, 35, 48, 61],
					[10, 23, 36, 49, 62],
					[11, 24, 37, 50, 63],
					[12, 25, 38, 51, 64]
				]
			},{
				name: 'diagonal',
				timing: 50,
				wipe: [
					[0],
					[1, 13],
					[2, 14, 26],
					[3, 15, 27, 39],
					[4, 16, 28, 40, 52],
					[5, 17, 29, 41, 53],
					[6, 18, 30, 42, 54],
					[7, 19, 31, 43, 55],
					[8, 20, 32, 44, 56],
					[9, 21, 33, 45, 57],
					[10, 22, 34, 46, 58],
					[11, 23, 35, 47, 59],
					[12, 24, 36, 48, 60],
					[25, 37, 49, 61],
					[38, 50, 62],
					[51, 63],
					[64]
				]
			}
];
var randomIndex = 0;
var logoIndex = 1;

function isLogoTile(id) {
	return (id >= 17 && id <=21) || (id >= 30 && id <= 34) || ( id >= 43 && id <= 47);
}

function logoNeedsBleedX(id) {
	return (id >= 17 && id < 21) || (id >= 30 && id < 34) || ( id >= 43 && id < 47);
}

function logoNeedsBleedY(id) {
	return (id >= 17 && id <=21) || (id >= 30 && id <= 34);
}

var currentWipe = {
	wipe: -1,
	subwipe: -1,
	img: -1,
	dir: 0
}
var interWipeDelay = 10000;
var wipeTimer = null;

var randomIndexes = [];		
		
function rnd(limit) {
	return Math.floor(Math.random() * limit);
}
		
function buildThumbnailContainers(withImage) {
	var i, el;
	var html, basehref, href, img;
	var rndIndex;
	var usedThumbnails = [];
				
	for (i=1; i<imageReps.length; i++) {
		if (docIDs[i] === docIDs[i-1]) {
			imageReps.splice(i, 1);
			credits.splice(i, 1);
			jobtitles.splice(i, 1);
			widths.splice(i, 1);
			heights.splice(i, 1);
			docIDs.splice(i, 1);
			jobcodes.splice(i, 1);
			i -= 1;
		}
	}
	if (withImage !== 0 && !withImage) {
		withImage = rnd(imgDisplaySrc.length-2)+2;
	}
	if (withImage === randomIndex && imageReps.length === 0) {
		withImage = logoIndex;
	}
		
	el = myGetElementById('searchresults');
	if (el) {
		removeClassName(el, 'thumbnaildefault');
		html = '';
		href = '';
		if (imageReps.length) {
			basehref = 'http://project.millerhare.com/public/search.asp';
		} else {
			basehref = '';
		}
		lastIndex = 0;
		for (i=0; i<thumbnailCount; i++) {
					
			//populate random wipe
			rndIndex = rnd(thumbnailCount);
			while (usedThumbnails[rndIndex]) {
				rndIndex = (rndIndex+1) % thumbnailCount;
			}
			usedThumbnails[rndIndex] = true;
			wipes[0].wipe[i] = [rndIndex];
					
			//build thumbnail container
			if (withImage>=0) {
				html += getImageHTML(withImage, i);
			} else {
				html += getImageHTML(-1, i);
			}
		}
					
		el.innerHTML = html;
		wipeTimer = window.setTimeout(doWipe, interWipeDelay);
	}
	currentWipe.img = withImage;
}
			
function setImage(srcIndex, destIndex) {
	var imgEl, aEl;
	var img;
	
	var bleedX, bleedY
				
	imgEl = document.getElementById('t' + destIndex);
	if (imgEl) {
		aEl = imgEl.parentNode;
		if (aEl) {
						
			img = getImageDetails(srcIndex, destIndex);
			
			bleedX = false;
			bleedY = false;
			if (srcIndex === logoIndex) {
				bleedX = logoNeedsBleedX(destIndex);
				bleedY = logoNeedsBleedY(destIndex);
			}
			toggleClassName(aEl, "bleedX", bleedX);
			toggleClassName(aEl, "bleedY", bleedY);
					
			aEl.href = img.href;
			imgEl.src = img.src;
			imgEl.width = img.w;
			imgEl.height = img.h;
			imgEl.style.top = img.t + 'px';
			imgEl.style.left = img.l + 'px';
		}
	}
}
			
function getImageDetails(srcIndex, destIndex) {
	var rndIndex;
	var img = {
		href: '',
		src: '',
		t: 0,
		l: 0,
		w: thumbnailSquare,
		h: thumbnailSquare
	}
				
	if (srcIndex<0 || (!imgDisplaySrc[srcIndex] && !imageReps.length)) {
		img.src = '/assets/spacer.gif';
		return img;
	}
				
				
	img.src = imgDisplaySrc[srcIndex];
	if (!img.src) {
		if (randomIndexes.length === 0) {
			for (rndIndex = 0; rndIndex < imageReps.length; rndIndex++) {
				randomIndexes[rndIndex] = rndIndex;
			}
		}
	
		rndIndex = rnd(randomIndexes.length);
		rndIndex = randomIndexes.splice(rndIndex, 1);
		if (rndIndex.length) {
			rndIndex = rndIndex[0];
		}
		
		img.href = 'http://project.millerhare.com/public/search.asp?i=' + docIDs[rndIndex];
		img.src = 'http://project.millerhare.com/secureimage/publicimage.asp?' + imageReps[rndIndex];
		img.t = (thumbnailSquare-heights[rndIndex])/2;
		img.l = (thumbnailSquare-widths[rndIndex])/2;
		img.w = widths[rndIndex];
		img.h = heights[rndIndex];
	} else {
		if (imageReps.length && img.src != 'mhl.jpg') {
			img.href = 'http://project.millerhare.com/public/search.asp?i=' + img.src.substr(0, 9);
		}
		img.src = '/assets/fp/' + img.src;
		img.t = -Math.floor(destIndex/thumbnailRow)*(thumbnailSquare+grid.y);
		img.l = -(destIndex % thumbnailRow)*(thumbnailSquare+grid.x);
		img.w = 1135;
		img.h = 435;
	}
	return img;
}
			
function getImageHTML(srcIndex, destIndex) {
			
	var img = getImageDetails(srcIndex, destIndex);
	var classNames = '';
	if (srcIndex === logoIndex) {
		if (logoNeedsBleedX(destIndex)) {
			classNames += ' bleedX';
		}
		if (logoNeedsBleedY(destIndex)) {
			classNames += ' bleedY';
		}
	}
	return '<a class="mhlthumbnailcontainer' + classNames + '" href="' + img.href + '"><img id="t' + destIndex + '" src="' + img.src + '" style="top:' + img.t + 'px;left:' + img.l + 'px;" width="' + img.w + '" height="' + img.h + '"></a>';
}
			
function doWipe() {
	var el, i, indexList;
	var rndImg;
	var thisWipe;
	var id;
				
	if (currentWipe.wipe < 0) {
		//new wipe
		currentWipe.wipe = rnd(wipes.length);
		
		rndImg = rnd(imgDisplaySrc.length);
		if (currentWipe.img != randomIndex && rndImg === currentWipe.img) {
			rndImg = (rndImg+1) % imgDisplaySrc.length;
		}
		if (rndImg === randomIndex && imageReps.length === 0) {
			rndImg = logoIndex;
		}
		currentWipe.img = rndImg;
		
		if (currentWipe.img<0) {
			currentWipe.img = -currentWipe.img;
		}
		if (Math.random() >= 0.5) {
			currentWipe.dir = 1;
			currentWipe.subwipe = 0;
		} else {
			currentWipe.dir = -1;
			currentWipe.subwipe = wipes[currentWipe.wipe].wipe.length-1;
		}
	}
				
	thisWipe = wipes[currentWipe.wipe];
	
				
	indexList = thisWipe.wipe[currentWipe.subwipe];
	for (i=0; i<indexList.length; i++) {
		id = indexList[i]
		if (currentWipe.img != logoIndex || isLogoTile(id)) {
			setImage(currentWipe.img, id);
		}
	}				
				
	currentWipe.subwipe += currentWipe.dir;
	if (currentWipe.subwipe >= thisWipe.wipe.length || currentWipe.subwipe < 0) {
		currentWipe.wipe = -1;
		wipeTimer = window.setTimeout(doWipe, interWipeDelay);
	} else {
		wipeTimer = window.setTimeout(doWipe, thisWipe.timing);
	}
}


		
