/******************************
 ***** UTITLITY FUNCTIONS *****
 ******************************/

/**
 * Utility function for randomizing parallel arrays using the Fisher-Yates shuffle algorithm
 */
function shuffle() {
	//retrieve list of passed in arrays
	var arrayList = arguments;

	if(arrayList.length > 0) {
		//make sure that all arrays have at least one element and are of the same length
		var total = 0;
		var avg = 0;
		for(var idx = 0; idx < arrayList.length; idx++) {
			if(!arrayList[idx].length || arrayList[idx].length == 0)
				throw Error("All arrays to shuffle must have at least one element.");
	
			total += arrayList[idx].length;
		} //end for
		avg = total / arrayList.length;
		for(var idx = 0; idx < arrayList.length; idx++)
			if(arrayList[idx].length != avg)
				throw Error("All arrays to shuffle must be of the same length.");
	
		//perform shuffling
		var i = arrayList[0].length;
		if(i == 0) return false;
	
		while(--i) {
			var j = Math.floor(Math.random() * (i + 1));
			swap(arrayList, i, j);
		} //end while
	} //end if
} //end function shuffle

function swap(swapArrays, idx1, idx2) {
	for(var idx = 0; idx < swapArrays.length; idx++) {
		var t1 = swapArrays[idx][idx1];
		var t2 = swapArrays[idx][idx2];
		swapArrays[idx][idx1] = t2;
		swapArrays[idx][idx2] = t1;
	} //end for
} //end function swap