/* toggle item */
function togItem(item){
	var x = item;
	if (eval(item + "_on")){
		modCollection(0,item,'show');
		eval(item + "_on = 0");
	} else {
		modCollection(1,item,'show');
		eval(item + "_on = 1");
	}
}


/* expand item */
function exItem(item){
	togItem(item);
}

/* collapse item */
function coItem(item){
	modCollection(0,item,'show');
}

/* expand all */
function exAll(){
	modCollection(1,'summary','show');
}

/* expand all books */
function exBooks(){
	modCollection(1,'book','show');
}

/* expand all periodicals */
function exPer(){
	modCollection(1,'periodical','show');
}

/* collapse all */
function coAll(){
	modCollection(0,'summary','show');
}

/* collapse all books */
function coBooks(){
	modCollection(0,'book','show');
}

/* collapse all periodicals */
function coPer(){
	modCollection(0,'periodical','show');
}

/* written by cookiecrook */
/* add or remove element className */
function modClass(bAdd,oElement,sClassName){
	if(bAdd){/* add class */
		if(oElement.className.indexOf(sClassName)==-1)oElement.className+=' '+sClassName;
	}else{/* remove class */
		if(oElement.className.indexOf(sClassName)!=-1){
			if(oElement.className.indexOf(' '+sClassName)!=-1)oElement.className=oElement.className.replace(' '+sClassName,'');
			else oElement.className=oElement.className.replace(sClassName,'');
		}
	}
	return oElement.className; /* return new className */
}

/* written by digiboy, modified for multiple classes by cookiecrook */
/* get an array of elements with the same className */
function getElementsByClass(sClassName) {
	var a, b, c, i, o, regex;
	b = document.getElementsByTagName("body").item(0);
	a = b.getElementsByTagName("*");
	o = new Array();
	
	// class surrounded by whitespace or start/end of line
	//regex = new RegExp('[^\\s]'+sClassName+'[$\\s]', 'i');
	//alert(regex);
	
	for (i = 0; i < a.length; i++) {
		if (a[i].className.indexOf(sClassName)!=-1){
		
				//only get exact matches
				thisMatch = 0;
				classNameArray = a[i].className.split(' ');
				for(j=0; j < classNameArray.length; j++) {
					//alert(j+' '+classNameArray[j]+' '+sClassName);
					if (classNameArray[j] == sClassName) {
						thisMatch = 1;
					}
				}
				if (thisMatch == 1) {
								o[o.length] = a[i];
				}

		//	o[o.length] = a[i];
		}
	}
	return o;
}

function modCollection(bAdd, sClassOfCollection, sClassAddedOrRemoved){
	var collection = getElementsByClass(sClassOfCollection);
	for(var i=0; i<collection.length; i++){
	//	alert(collection[i].className);
		modClass(bAdd, collection[i], sClassAddedOrRemoved);
	}
}