	
addLoadEvent(initializeSectionExpandCollapse);

function initializeSectionExpandCollapse() 
		{
			if(typeof window.disableExpandCollapse == "undefined")
				{
					addSectionExpandCollapse();  		 
				}
		}


function ajaxAddSectionExpandCollapse()
	{
		addSectionExpandCollapse();
	}


function addSectionExpandCollapse()
		{
		 	// find all elements that can expand other elements
		 	// to speed the script up on large pages which may or especially
		 	//  may not have collapsible areas, define a collapsibleTag.  
		 	//  Defining a tag for the collapsible section
		 	//  narrows down the work the browser has to do to find them all.  Setting it to
		 	//  a nonexistant tag value will prevent the script from applying any
		 	//  expand/collapse logic to the page.  
		 	if(typeof collapsibleTag == 'undefined')
				{		 	
					var collapsibleSections = getElementsByClassName(document,"*","collapsibleSection");
		 		}
		 	else
		 		{
		 			if(typeof collapsibleAreaID != 'undefined')
		 				{
		 					var collapsibleArea = document.getElementById(collapsibleAreaID);
		 					if(collapsibleArea)
		 						{	
		 							var collapsibleSections = getElementsByClassName(collapsibleArea,collapsibleTag,"collapsibleSection"); 				
		 						}
		 					else
		 						{
		 							var collapsibleSections = getElementsByClassName(document,collapsibleTag,"collapsibleSection"); 				
		 						}
		 				}
		 			else
		 				{
			 				var collapsibleSections = getElementsByClassName(document,collapsibleTag,"collapsibleSection"); 				
			 			}
		 		}
		 	
		  
		 	// for each collapsible section...
		 	for(i=0; i< collapsibleSections.length; i++)
				{					
					//  get all sections that respond to this container and add it
					if(typeof collapsibleResponderTag != 'undefined')
						{
							var respondingElements = getElementsByClassName(collapsibleSections[i],collapsibleResponderTag, "expandcollapse");
						}
					else
						{
							var respondingElements = getElementsByClassName(collapsibleSections[i],"*", "expandcollapse");
						}
					
					
					// create array to hold the class information for each element; this will be attached to the section itself
					// each element in the array consists of [0] reference to the responding element, [1] its class when expanded, 
					// and [2] its class when collapsed
					var sectionRespondingElements = new Array();
					
					for (j=0;j<respondingElements.length;j++)
						{
							sectionRespondingElements[j] = new Array();
							sectionRespondingElements[j][0] = respondingElements[j];
							if (respondingElements[j].getAttribute("classwhensectionexpanded"))
								{
									sectionRespondingElements[j][1] = respondingElements[j].getAttribute("classwhensectionexpanded");
								}
							else
								{
									sectionRespondingElements[j][1] = ""
								}
							if (respondingElements[j].getAttribute("classwhensectioncollapsed"))
								{
									sectionRespondingElements[j][2] = respondingElements[j].getAttribute("classwhensectioncollapsed");
								}
							else
								{
									sectionRespondingElements[j][2] = ""
								}								
						}
					
					// assign this array to the section
					collapsibleSections[i].sectionRespondingElements=sectionRespondingElements;					
					
					// now find all the expanders and collapsers in the section.  Add click events to them.		
								
					var sectionExpanders = getElementsByClassName(collapsibleSections[i],"*", "sectionexpander");					
					var sectionCollapsers = getElementsByClassName(collapsibleSections[i],"*", "sectioncollapser");
					
	
					for (ex=0;ex<sectionExpanders.length;ex++)
						{
							sectionExpanders[ex].mySectionToExpand=collapsibleSections[i];	
							if(!sectionExpanders[ex].expanderEventAttached || sectionExpanders[ex].expanderEventAttached == false)	
								{
									addEvent(sectionExpanders[ex],"click",expandSection);
									sectionExpanders[ex].expanderEventAttached = true;
								}
							
							
							if(sectionExpanders[ex].type && sectionExpanders[ex].type=="radio")
								{	
									radiosInGroup = sectionExpanders[ex].form.elements[sectionExpanders[ex].name];
									for(var o=0;o<radiosInGroup.length;o++)
										{								
											if (radiosInGroup[o]!=sectionExpanders[ex])
												{	
													if(!radiosInGroup[o].mySectionToCollapse) radiosInGroup[o].mySectionToCollapse = new Array()								
													radiosInGroup[o].mySectionToCollapse.push(collapsibleSections[i]);
													if(!radiosInGroup[o].collapseEventAttached || radiosInGroup[o].collapseEventAttached == false)
														{
															addEvent(radiosInGroup[o],"click",collapseSection);
															radiosInGroup[o].collapseEventAttached = true;
														}
												}										
										}
								}
						}
						
					for (ex=0;ex<sectionCollapsers.length;ex++)
						{	
 							sectionCollapsers[ex].mySectionToCollapse = new Array();
							sectionCollapsers[ex].mySectionToCollapse.push(collapsibleSections[i]);						
							if (!sectionCollapsers[ex].collapserEventAdded || sectionCollapsers[ex].collapserEventAdded==false)
								{									
									addEvent(sectionCollapsers[ex],"click",collapseSection);															
									sectionCollapsers[ex].collapserEventAdded = true;
								}
						}						
				}
		 
		}			
					
		
function expandSection()
	{	
		var sectionsToChange = this.mySectionToExpand.sectionRespondingElements;		
		for(var i=0;i<sectionsToChange.length;i++)
			{	
				var currentElement = sectionsToChange[i][0];				
				var elementNewClass = sectionsToChange[i][1];
				var elementOppositeClass = sectionsToChange[i][2];
				
				if(jscss("check", currentElement, elementOppositeClass) == true)
					{
						jscss("swap", currentElement, elementOppositeClass, elementNewClass);
					}
				else if (jscss("check", currentElement, elementNewClass) == false)
					{
						jscss("add", currentElement, elementNewClass);
					}				
			}
	}

function collapseSection()	
	{ 	
		var sectionsToChange = new Array();
		for (x=0;x<this.mySectionToCollapse.length;x++)
			{
				sectionsToChange = sectionsToChange.concat(this.mySectionToCollapse[x].sectionRespondingElements);
			}
		//alert(sectionsToChange.length);
		for(var i=0;i<sectionsToChange.length;i++)
			{
				var currentElement = sectionsToChange[i][0];
				var elementNewClass = sectionsToChange[i][2];
				var elementOppositeClass = sectionsToChange[i][1];
				
				if(jscss("check", currentElement, elementOppositeClass) == true)
					{	
						jscss("swap", currentElement, elementOppositeClass, elementNewClass);
					}
				else if (jscss("check", currentElement, elementNewClass) == false)
					{	
						jscss("add", currentElement, elementNewClass);
					}				
			}
	}
	
	
	

