/* toggleViewArrow.js
 * Creates a toggle (show/hide) widget that uses an arrow
 */
 
addLoadEvent(insertArrow);

/* Injects the arrow image into the "button" */
function insertArrow() {
	var tabuttons = document.getElementsByTagName("a");
	var arrow = document.createTextNode("\u25B9");
	var arrow_a = document.createElement("a");
	arrow_a.appendChild(arrow);
	arrow_a.className = "arrow";
	arrow_a.setAttribute("href", "#");
	
	for (var i = 0; i < tabuttons.length; i++) {
		if (tabuttons[i].className == "toggle-arrow-button") {
			tabuttons[i].parentNode.insertBefore(arrow_a, tabuttons[i]);
			arrow_a.onclick = function() { toggleArrow(this); return false;}
			tabuttons[i].onclick = function() { toggleArrow(this); return false;}
		}
	}	
}

/* Handles the click event on the "button" text and arrow image */
function toggleArrow(clicked) {
	//\u25BF
	var div = clicked.parentNode;
	var arrow = div.firstChild;
	
	if (arrow.className == "arrow closed") {
		div.className = "toggleOpen";
	}
		
}
