/**
 * Functions to show and hide blocks on a HTML page.
 * 
 * @author Matt Painter
 */


// Hide all blocks with the hiddenBlock class on page load. This increases accessibility for users
// with Javascript turned off as the default is to show all hidden blocks. 
$(document).ready(function() {
	$(".hiddenBlock").css({display: "none"});
});

/**
 * Toggles the visilibity of a selected block.
 * 
 * @param blockID id of block to toggle visibility of. 
 * @param link link that the user clicks on to change visibility. If the link contains text, and the labels
 *             parameter is empty, the link is updated with default 'more detail...' / 'hide detail...' text.
 * @param labels optional two-element array containing custom text equivalent for 'more detail...' and 
 *        'hide detail', respectively.
 */
   function toggleVisibility(blockID, link) {
	block = document.getElementById(blockID);
	labels = arguments[2];
	
	if (block.style.display == "none") {

		// Reset display to default
		block.style.display = "";
		
		// Only update invoking link for links that have text (i.e., not wrappers around images)
		if (link.textContent != "") {
			link.innerHTML = typeof(labels) == "undefined" ? "hide detail&hellip;" : labels[1];
		}
	}	
	else {
		block.style.display = "none";
		
		if (link.textContent != "") {
			link.innerHTML = typeof(labels) == "undefined" ? "more detail&hellip;" : labels[0];
		}
	}
}


/**
 * List of contracted relationships for the current page, used internally only.
 */
var relationshipsContracted = new Array();

/**
 * Expands or contracts a list of relationships. This function works on a class so can show or hide
 * multiple table rows.
 *
 * @param blockClass class of rows to show/hide
 * @param link link that the user clicks on to expand/contract relationship list.
 */
function expandContractRelationshipList(blockClass, link) {
	if (relationshipsContracted[blockClass]) {
		$("." + blockClass).css({display: "none"});
		link.innerHTML = "see more of this list&hellip;";
	}
	else {
		$("." + blockClass).css({display: ""});
		link.innerHTML = "contract this list&hellip;";
	}
		
	relationshipsContracted[blockClass] = !relationshipsContracted[blockClass];
}

					
					