// this MUST be called AFTER the document object is loaded.
function executeAccordion(){
	var allDivs = document.getElementsByTagName('div');
	
	for(var c = 0; c<allDivs.length; c++){
		if(allDivs[c].className =='accordion_container') {
		
			//execute only if there is an element on the page with the proper name
			var headings = allDivs[c].getElementsByTagName('h3');
			var sections = allDivs[c].getElementsByTagName('blockquote');
			
			for(var i = 0; i<headings.length; i++){
				//set initial classes for each element
				headings[i].className = headings[i].className + ' ac_closed';
				sections[i].className = sections[i].className + ' ac_hidden';
				
				//set behavior for onclick event
				headings[i].onclick = function() {
					//set initial values
					var thisSection = this;
					do thisSection = thisSection.nextSibling;
					while (thisSection && thisSection.nodeType != 1){
						//console.log(thisSection.nodeType);
					};
					
					//toggle class of heading and section
					var thisClass = this.className;
					if(thisClass.indexOf('ac_closed') != -1) {
						//closed; open
						this.className = thisClass.replace(/ac_closed/, 'ac_open');
						//toggle class of section
						thisSection.className = thisSection.className.replace(/ac_hidden/, 'ac_show');
					} else {
						//open; closed
						this.className = thisClass.replace(/ac_open/, 'ac_closed');
						//toggle class of section
						thisSection.className = thisSection.className.replace(/ac_show/, 'ac_hidden');
					}
				}; //end onclick function
			} //end loop
		} else {
			//containers do not exist on this page, do nothing
			//console.log('Div #'+c+' not applicable');
		}
	}
};
//always check to see if the addLoadEvent function exists before trying to call it!
if(typeof addLoadEvent == 'function'){
	addLoadEvent(executeAccordion);
}