//  Copyright (c) 2006 Matthew Ellison Consulting Ltd
//  You are free to use or modify this code if you reference the
//  author's email address matthew@ellisonconsulting.com
//  in a comment within your code

function expandCollapse(elementClicked) {

	var tagClicked = elementClicked.tagName;

	// Store the A element in aClicked
	var aClicked;	
	if (tagClicked == "IMG")
		{ aClicked = elementClicked.parentNode }
	   else
		{ aClicked = elementClicked }

	// Store the IMG element in imgClicked, move to the DIV element and store 
	// this in divExpCollapse. "If else" allows for the possibility of a line
	// break before the IMG element for Mozilla

	var imgClicked;

	if (aClicked.firstChild.nodeType==3)
	{
		imgClicked = aClicked.firstChild.nextSibling;
	}
	else
	{
		imgClicked = aClicked.firstChild;
	}

	var aParent = aClicked.parentNode;

	var divExpCollapse;

	if (aParent.nextSibling.nodeType==3)
	{
		divExpCollapse = aParent.nextSibling.nextSibling;
	}
	else
	{
		divExpCollapse = aParent.nextSibling;
	}


	// If the divExpCollapse node has a class name of either "collapsed" or "expanded"
	// then switch from one to the other.  If it has neither, then do nothing.
	// classAttributeName() equates to "className" for IE5+ and to "class" for Mozilla

	if (divExpCollapse.getAttribute(classAttributeName()) == "collapsed")

		{ divExpCollapse.setAttribute(classAttributeName(),"expanded");
		  imgClicked.setAttribute("src","images/expanded.gif"); }
	     else

		{ if (divExpCollapse.getAttribute(classAttributeName()) == "expanded")
			{ divExpCollapse.setAttribute(classAttributeName(),"collapsed");
		  	  imgClicked.setAttribute("src","images/collapsed.gif");
			}
		}  
}