if (!exclusions) {
	var exclusions = new Array();
	// exclusions are divs that contain multiple sub-divs, ie that we want to take out in one without making all their subdivs disappear first
	// these are defined on a page-by-page basis in the <script> block
	// This might not be working properly. Double check it.
}

function divToggle(i) {
	if (i.style.visibility == 'hidden') {
		i.style.visibility = 'visible';
	} else {
		i.style.visibility = 'hidden';
	}
}
function divShuffle(x) {
	var ds = document.body.getElementsByTagName('div');
	var di = new Array();
	for (s=0; s<ds.length; s++) {
		if (ds[s].getElementsByTagName('div').length == (x-1) && ds[s].id != 'square' && ds[s].id != 'subsquare' && !isExcluded(ds[s])) {
			di.push(ds[s]);
		}
	}
	if (x == 2) {
		for (e=0; e<exclusions.length; e++) {
			if (document.getElementById(exclusions[e])) {
				di.push(document.getElementById(exclusions[e]));
			}
		}		
	}
	else if (x == 1) {
		for (e=0; e<exclusions.length; e++) {
			if (document.getElementById('sub' + exclusions[e])) {
				di.push(document.getElementById('sub' + exclusions[e]));
			}
		}		
	}
	var du = new Array(di.length);
	var df = new Array(di.length);
	for (i=0; i<du.length; i++) {
		du[i] = 0;
	}
	var flag;
	for (d=0; d<=di.length-1; d++) {
		flag = false;
		while (!flag) {
			u = Math.floor(Math.random()*di.length);
			if (du[u] == 0) {
				df[d] =  di[u];
				du[u] =  1;				
				flag = true;
			}
		}
	}
	return df;
}

function isExcluded(node) {
	var excluded = '#';
	for (e=0; e<exclusions.length; e++) {
		excluded += exclusions[e];
		excluded += '#';
	}
	while (node.parentNode) {
		var myStr = '#' + node.parentNode.id + '#';
		if (excluded.match(myStr)) {
			return true;
		}
		else {
			node = node.parentNode;
		}
	}
	return false;
}

var abolescoLayer = 1;
var abolescoDirection = 'down';
var abolescoRunning = false;

function abolesco () {
	if (!abolescoRunning) {
		abolescoRunning = true;
		var v = divShuffle(abolescoLayer);
		_abolesco ();
	}

	function _abolesco() {
		if (v.length > 0) {
			divToggle(v.pop());
			abolescoTimeout = setTimeout(_abolesco, 5);
		}
		else {
			abolescoRunning = false;
			switch(abolescoLayer) {
				case 0:
					abolescoLayer++;
					abolescoDirection = 'down';
					break;
				case 3:
					// This can be increased if we start working with lots of nested divs/'layers'
					// Just alter
					abolescoLayer--;
					abolescoDirection = 'up';
					break;
				default:
					if (abolescoDirection == 'down') {
						abolescoLayer++;
					} else 	if (abolescoDirection == 'up') {
						abolescoLayer--;
					}
					abolesco();
					break;
			}
		}
	}
}