addLoadListener(initExpandCollapse);

function initExpandCollapse()
{
	var modules = 	[document.getElementById("panel1"),	document.getElementById("panel2"), document.getElementById("panel3"), document.getElementById("panel4"), document.getElementById("panel5")];
	
	for (var i in modules)
	{
		if (modules[i]!=null)
		{
			var h3s = modules[i].getElementsByTagName("h3");

			for (var i = 0; i < h3s.length; i++)
			{
				var newA = document.createElement("a");
				newA.setAttribute("href", "#");
				newA.setAttribute("title", "Expand/Collapse");
				attachEventListener(newA, "mousedown", mousedownExpandCollapse, false);
				newA.onclick = clickExpandCollapse;
				
					var newImg = document.createElement("img");
					newImg.setAttribute("src", "images/btn-expandcollapse.gif");
					newImg.setAttribute("alt", "Expand/Collapse");
					newA.appendChild(newImg);
					
				h3s[i].appendChild(newA);

				//collapse all by default
				addClass(h3s[i].parentNode, "collapsed");
			}
		}
	}
	
	return true;
};




function mousedownExpandCollapse(event)
{
	if (typeof event == "undefined")
	{
		event = window.event;
	}
	
	if (typeof event.stopPropagation != "undefined")
	{
		event.stopPropagation();
	}
	else
	{
		event.cancelBubble = true;
	}
	
	return true;
};




function clickExpandCollapse()
{
	if (!hasClass(this.parentNode.parentNode, "collapsed"))
	{
		addClass(this.parentNode.parentNode, "collapsed");
	}
	else
	{
		removeClass(this.parentNode.parentNode, "collapsed");
	}
	
	return false;
};