
var showhide = {
	
	exclusive_show: true,
	list_id: 'showhide-list',
	showall_id: 'showhide-showall',
	parent_tag: 'DT',
	click_tag: 'A',
	child_tag: 'DD',
	

	init_showhide: function() {
		var shEl = document.getElementById(showhide.list_id);
		var saEl = document.getElementById(showhide.showall_id);
		if(!shEl) return;
		
		if(saEl) {
			var saLnk = document.createElement('A');
			var saLnkTxt = document.createTextNode('Click here');
			var saTxt = document.createTextNode(' to expand all.');
			saLnk.href = '';
			saLnk.onclick = showhide.showAll;
			saLnk.appendChild(saLnkTxt);
			saEl.appendChild(saLnk);
			saEl.appendChild(saTxt);
		}
		
		var chEl = shEl.firstChild;
		do {
			if(chEl.nodeType == 1 && chEl.tagName.toUpperCase() == showhide.parent_tag.toUpperCase()) {
				var shLnk = showhide.click_tag ? chEl.getElementsByTagName(showhide.click_tag) : Array(chEl);
				if(shLnk[0]) shLnk[0].onclick = showhide.doShowHide;
			}
			chEl = chEl.nextSibling;
		} while(chEl);
	},
	
	showAll: function() {
		try {
			var shEl = document.getElementById(showhide.list_id);
			var shPa = shEl.getElementsByTagName(showhide.parent_tag);
			var shCh = shEl.getElementsByTagName(showhide.child_tag);
			for(var i=0; i<shPa.length; i++) {
				shPa[i].className = shPa[i].className + ' on';
			}
			for(var i=0; i<shCh.length; i++) {
				shCh[i].className = shCh[i].className + ' show';
			}
		} catch(e) {}
		return false;
	},

	doShowHide: function(showAll) {
		var srcEl = this;

		if(srcEl.parentNode.getElementsByTagName(showhide.child_tag).length) {
			chdEl = srcEl.parentNode.getElementsByTagName(showhide.child_tag)[0];
		} else {
			chdEl = srcEl.parentNode.nextSibling;
			while(chdEl && (chdEl.nodeType != 1 || chdEl.tagName.toUpperCase() != showhide.child_tag.toUpperCase()) ) chdEl = chdEl.nextSibling;
		}

		if(showhide.exclusive_show) {
			var shEl = document.getElementById(showhide.list_id);
			var shPa = shEl.getElementsByTagName(showhide.parent_tag);
			var shCh = shEl.getElementsByTagName(showhide.child_tag);
			for(var i=0; i<shPa.length; i++) {
				if(showhide.click_tag) {
					var shCl = shPa[i].getElementsByTagName(showhide.click_tag);
					if(shCl[0]) shCl[0].className = shCl[0].className.replace(/\bon\b/i, '');
				}
				shPa[i].className = shPa[i].className.replace(/\bon\b/i,'');
			}
			for(var i=0; i<shCh.length; i++) {
				if(shCh[i].className.indexOf('nohide')==-1 && (!chdEl || chdEl != shCh[i]) ) {
					shCh[i].className = shCh[i].className.replace(/\bshow\b/i,'');
				}
			}
		}
		if(chdEl) {
			var hide = (chdEl.className.match(/\bshow\b/i));
			chdEl.className = hide ? chdEl.className.replace(/\bshow\b/i,'') : chdEl.className + ' show';
			if(!hide) srcEl.className = srcEl.className + ' on';
			if(!hide && showhide.click_tag && srcEl.parentNode) srcEl.parentNode.className = srcEl.parentNode.className + ' on';
		}

		return false;
	}
};

var oldonload = window.onload;
window.onload = (typeof oldonload == 'function') ? function() { oldonload(); showhide.init_showhide(); } : showhide.init_showhide;
