/* image pairs for header */
var imgs = new Array(
50, 60,
51, 53, 
52, 54,
57, 66,
81, 320,
91, 411,
97, 211,
85, 104,
107, 699,
116, 183,
122, 123,
124, 130,
125, 126, 
128, 129,
127, 131,
142, 144, 
147, 149,
152, 155,
495, 158,
168, 192,
171, 304,
195, 198,
204, 210,
213, 216,
257, 258,
240, 263,
276, 696,
277, 279,
278, 280,
281, 282,
283, 299,
284, 311,
201, 291,
290, 294,
292, 293,
329, 323,
335, 336,
452, 463,
457, 469,
480, 486,
489, 492, 
498, 501,
507, 513,
264, 307,
697, 496,

839, 844,
849, 850,
852, 851,
854, 855, 
865, 1024,
863, 1025,
876, 880,
878, 879, 
881, 882,
927, 929,
932, 935,
933, 936,
931, 934
);
function randomImageSet() {
	imgSet = Math.floor(Math.random() * imgs.length/2);
	writeImage(imgs[imgSet*2 + 1], 'right', false);
	writeImage(imgs[imgSet*2], 'left', false);
}
function imageSets() { 
	for (i=0; i<imgs.length/2; i++) {
		var w = (i > 44 ? 260 : 205);
		document.writeln('<div class="imageset" style="width: ' + w + 'px;">');
		writeImage(imgs[i*2+1], 'right', true);
		writeImage(imgs[i*2], 'left', true);
		document.writeln('</div>');
	}
}
function allImages() {
	for (i=50; i<=1125; i++) {
		document.writeln('<div style="display: inline; float: left; min-width: 100px; min-height: 100px; margin: 5px;">');
		document.write(i + '<br />');
		writeImage(i, 'left', false);
		document.writeln('</div>');
	}
}
function writeImage (imgNo, whichImg, writeNum) {
	if ((imgNo >= 527 && imgNo <= 633) || (imgNo >= 838 && imgNo <= 940) || (imgNo >= 948 && imgNo <= 1050) 
		|| imgNo == 1110 || (imgNo >= 1115 && imgNo <= 1118) || imgNo == 1120 || imgNo == 1121 || imgNo == 1125) 
		whichImg = whichImg + "-h";
	with (document) {
		write('<a href="http://digital.library.colostate.edu/carnations/image/' + imgNo + '.jpg">');
		write('<img src="http://digital.library.colostate.edu/carnations/image/icon' + imgNo + '.jpg" alt="" class="image-' + whichImg + '" title="Random image from the collection (click to enlarge)" />');
		writeln('</a>');
		if (writeNum) 
			write('<span class="image' + whichImg + '">' + imgNo + '</span>');
	}
}

/* random images for home page */
function getRandImageNo() { 
	do {
	imgNo = Math.floor(Math.random()*1143 + 1);
	} while (
		// not attractive
		(imgNo >= 413 && imgNo <=478) ||
		(imgNo >= 534 && imgNo <=633) ||
		(imgNo >= 942 && imgNo <=946) ||
		(imgNo >= 988 && imgNo <=1022) ||
		(imgNo >= 1056 && imgNo <=1106) ||
		// IP restricted: book cover, magazine cover, newspaper advertisement, newspaper article, newspaper page
		(imgNo == 87) ||
		(imgNo == 97) ||
		(imgNo == 99) ||
		(imgNo == 100) ||
		(imgNo == 122) ||
		(imgNo == 123) ||
		(imgNo == 222)
	);
	return imgNo;
}
function getImage(imgNo) { 
	return 'http://digital.library.colostate.edu/carnations/image/' + imgNo + '.jpg'; 
}
function changeImage() {
	imgNo = getRandImageNo(); 
	imgURL = getImage(imgNo);
	document.getElementById('imglink').href = imgURL;
	document.getElementById('img').src = imgURL;
}
function randImage() {
	imgNo = getRandImageNo(); 
	imgURL = getImage(imgNo);
	document.write('<a id="imglink" href="' + imgURL + '">');
	document.write('<img id="img" src="' + imgURL + '" alt="random image from the collection" onerror="changeImage()" />');
	document.writeln('</a>');
//	document.writeln('<p id="imgCaption">Random image from the collection (Click to enlarge)</p>');
}
