// Specify the number of columns in the 'archSet' array:

var numCols = 7;

//

var archSet = new Array(

//Conc.	Year	Prog.	Poster	Photos	Title				Conductor(s)
'4',	'2009',	'pdf',	'jpg',	'',	'North Winds, South Winds',	'Ryan Youens',
'3',	'2009',	'pdf',	'jpg',	'11',	'Distant Shores',		'Ashley Hopkins',
'2',	'2009',	'pdf',	'jpg',	'',	'Solar Winds',			'Ewan Clark, Ryan Youens',
'1',	'2009',	'pdf',	'jpg',	'21',	'British Band Classics',	'Ewan Clark',
'4',	'2008',	'pdf',	'jpg',	'',	'Rhapsody in Red, White & Blue','Ewan Clark',
'3',	'2008',	'pdf',	'jpg',	'',	'Colours of France',		'Ewan Clark',
'2',	'2008',	'pdf',	'jpg',	'18',	'Opera Favourites',		'Ashley Hopkins',
'1',	'2008',	'pdf',	'jpg',	'5',	'Enchanted Tales',		'Ewan Clark',
'4',	'2007',	'pdf',	'jpg',	'',	'40th Anniversary',		'Hugh Dixon, Peter Thomas, Ewan Clark',
'3',	'2007',	'pdf',	'jpg',	'3',	'Postcards',			'Opeloge Ah Sam',
'2',	'2007',	'pdf',	'jpg',	'',	'Land & Sea',			'Yih-hsin Huang',
'1',	'2007',	'pdf',	'jpg',	'',	'Russia',			'Ashley Hopkins',
'4',	'2006',	'pdf',	'',	'',	'Pageant',			'John Rimmer',
'3',	'2006',	'pdf',	'',	'',	'[festival]',			'Ashley Hopkins',
'2',	'2006',	'pdf',	'jpg',	'',	'Stage & Screen',		'Peter Thomas',
'1',	'2006',	'pdf',	'',	'',	'Old Wine in New Bottles',	'Adrian Raven',
'4',	'2005',	'pdf',	'',	'5',	'Summer Celebration',		'Andrew Marshall',
'3',	'2005',	'pdf',	'',	'',	'Classics',			'Adrian Raven',
'2',	'2005',	'pdf',	'',	'',	'New Zealand',			'Peter Thomas',
'1',	'2005',	'pdf',	'',	'',	'French Music',			'Dr. David G. Herbert',
'4',	'2004',	'',	'jpg',	'',	'Finale Concert &#39;04',	'Peter Thomas',
'3',	'2004',	'gif',	'',	'',	'[unnamed]',			'David Kay, Hamish Arthur',
'2',	'2004',	'gif',	'jpg',	'',	'A Mighty Wind Orchestra',	'Peter Thomas',
'1',	'2004',	'gif',	'',	'',	'Dance Around The World',	'Jonathan Baker',
'3',	'2003',	'gif',	'',	'',	'Jazz Classics',		'Adrian Raven',
'1',	'2003',	'gif',	'',	'',	'Stage & Screen',		'Peter Thomas',
'1',	'2002',	'gif',	'jpg',	'',	'The Best of British',		'Adrian Raven',
'3',	'2001',	'gif',	'jpg',	'',	'The Lord of the Rings',	'Adrian Raven',
'2',	'2001',	'gif',	'jpg',	'',	'Winds of the World',		'Adrian Raven',
'1',	'2001',	'gif',	'jpg',	'',	'Russian Masters',		'Adrian Raven',
'1',	'1998',	'pdf',	'',	'',	'No Strings Attached',		'Peter Thomas',
'1',	'1997',	'pdf',	'',	'',	'[unnamed]',			'Peter Thomas, Grant Burns'
);

function displayThumbs(include) {
	if (include==null) document.getElementById('search').onkeyup = executeSearch;
	document.getElementById('contentB').innerHTML = '';
	var location = "archive/"
	var numThumbs = archSet.length / numCols;
	if (include!=null) numThumbs = include.length;
	for (i=0; i<numThumbs; i++) {
		var k = i;
		if (include!=null) k = include[i];
		var newDiv = document.createElement("div");
		newDiv.className = 'archMenu';
		newDiv.setAttribute('id', 'inArchDiv'+i);
		var photos = '';
		var prog = '';
		var postr = '';
		if(archSet[k*numCols + 4] != '') {
			photos = "<a href='javascript:void(0)' onclick='loadGalleryPage(" + k + ");'><img class='arcimg' src='images/camera.png' title='Photos' alt='' /></a>";
		}
		if(archSet[k*numCols + 2] != '') {
			prog = "<a href='" + location + "AWO_" + archSet[k*numCols+1] + "_" + archSet[k*numCols] + "." + archSet[k*numCols+2] + "' target='_blank'><img class='arcimg' src='images/prog.jpg' title='Programme' alt='' /></a>";
		}
		if(archSet[k*numCols + 3] != '') {
			postr = "<a href='" + location + "AWO_" + archSet[k*numCols+1] + "_" + archSet[k*numCols] + "." + archSet[k*numCols+3] + "' target='_blank'><img class='arcimg' src='images/postr.jpg' title='Poster' alt='' /></a>";
		}
		newDiv.innerHTML = prog + postr + photos + "<span class='f1'>" + archSet[k*numCols + 1] + "</span><br /><span class='f2'>" + archSet[k*numCols + 5] + "</span><br /><span class='f3'>" + archSet[k*numCols + 6] + "</span>";
		document.getElementById('contentB').appendChild(newDiv);
	}
}

// The following deals with the archive search function.

function executeSearch() {
	var area = document.getElementById('search');
	if (area.value == "") {
		displayThumbs(null);
	} else {
		var input = area.value.split(" ");
		var resultsFinal = new Array();
		for(i=0; i<input.length; i++) {
			if (input[i] != '') {
				var results = new Array();
				for (l=0; l<archSet.length; l++) {
					if (contains(archSet[l].toLowerCase(), input[i].toLowerCase()))
						results.push(l);
				}
				for(j=0; j<results.length; j++) {
					results[j] = (Math.floor(parseInt(results[j])/numCols));
				}
				results = unique(results);
				if (i!=0) {
					var preFin = new Array();
					for(k=0; k<results.length; k++) {
						for(m=0; m<resultsFinal.length; m++) {
							if (resultsFinal[m]==results[k])
								preFin.push(results[k]);
						}
					}
					resultsFinal = preFin.slice();
				} else {
					resultsFinal = results.slice();
				}
			}
		}
		displayThumbs(resultsFinal);
	}
}

function contains(string1, string2) {
	return string1.indexOf(string2) >= 0 ? true : false
}

function unique(arr) {
	if(!Array.indexOf){
		Array.prototype.indexOf = function(obj){
			for(var i=0; i<this.length; i++){
				if(this[i]==obj)
					return i;
			}
			return -1;
		}
	}
	var a = [], i, l = arr.length;
	for( i=0; i<l; i++ ) {
		if( a.indexOf( arr[i], 0 ) < 0 ) { a.push( arr[i] ); }
	}
	return a;
}