/*
* Executes Javascript on page load
* From http://simonwillison.net/2004/May/26/addLoadEvent/
* Credit goes to Simon Willison
*/
function addLoadEvent(func) {
	var oldonload = window.onload;
	
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		};
	}
}

addLoadEvent(RegisterAnchorRegisters);


/*
* Get elements from class name
*/
function GetElementsByClassName(class_name, root_node) {
	//if a default root node isnt given, make it the whole doc
	if (root_node === null) { root_node = document; }
	
	//get all of the nodes within the root node
	var all_elements = root_node.getElementsByTagName('*');

	//scan through the nodes and get nodes that match the class name
	var elements = [];
	
	if (all_elements !== null) {
		for(var i=0, j=0; i < all_elements.length; i++) {
			//test whether the class name exists in the nodes class name
			if (all_elements[i].className == class_name) {
				 elements[j++] = all_elements[i];
			}
		}
	}
	
	//return the elements that matches (if any)
	return elements;
}


/*
* Register all of the anchors marked as expandable buttons
*/
function RegisterAnchorRegisters() {
	var links = GetElementsByClassName("extra_link",document.body);
	
	for (var i=0;i< links.length;i++) {
		links[i].onmousedown = function() {
			var hiddenContent = GetElementsByClassName('extra_content',this.parentNode)[0];
			
			if (hiddenContent.style.display=="block") {
				hiddenContent.style.display="none";
			} else {
				hiddenContent.style.display="block";
			}
		}
	}
}
