/* ==================================================================
 *  indexlist-update.js
 *  Makes definition lists interactive: show/hide data by clicking on term
 *  Requires: pcclib.js
 * ------------------------------------------------------------------
 *  owner: PCC Web Team <webteam@pcc.edu>
 *  author: Gabriel McGovern <gabriel.mcgovern@pcc.edu>
 *  created: 2007-07-20 
 *  modified: 
 * ================================================================== */

function filterIndexList(indexlistId, className) {
	if (!DOM) return;														// Must have DOM Control to continue
	//if (!resetId) var resetId = "";											// init this optional function variable
	var pList = document.getElementById("program-list"); 						// identify full list (of lists)
	var h4, hidden, j, li, lis, i, ul, uls = pList.getElementsByTagName("ul");  // get lists, and init other vars
	
	for (i=0; ul=uls[i]; i++) {												// loop through lists
		j, li, lis = ul.getElementsByTagName("li");							// get list items
		for (j=0, hidden=0; li=lis[j]; j++) {								// loop through items, reset hidden to 0
		//setTimeout("alert('hello')",1250);
			if( className && !li.className.hasClass(className) ){			// it does not match class
				li.className = li.className.addClass('hide');					// so hide it
				hidden+=1;														// oh, nad keep count too
			}
			else{																// it does match?
				li.className = li.className.removeClass('hide');				// then we better show it
			}
		}
		h4 = ul;															// starting at the list
		do h4 = h4.previousSibling;											// find the previous tag (should be an h4)
		while (h4 && h4.nodeType != 1);										// ignore whitespace siblings
		if(h4.nodeName == "H4"){											// if it really is an h4 (it better be!)
			if (hidden==lis.length){											// did we hide all the lists items?
				h4.className = h4.className.addClass('hide');					// then hide the heading
				ul.className = ul.className.addClass('hide');					// and the list (to remove margins, padding)
			}
			else{																// items still showing?
				h4.className = h4.className.removeClass('hide');				// then un-hide the heading
				ul.className = ul.className.removeClass('hide');				// and the list
			}
		}
	}
	return false;
}
