<!-- 
// this script is used to show/hide divs onclick
// taken from Blogger Help/Hacks at
// http://help.blogger.com/bin/answer.py?answer=897&topic=41
/*
heavily modified by:
Gerry Quach
State Library of New South Wales
26 July 2006

Bugfixes: 
- 7 August 2006
- 17 August 2006: use of "undefined" or undefined caused JS errors (inc. in IE5); correct way to test for undefined variableis: if typeof(variable) == 'undefined'

New features
- 6 November 2007: set a div's class to "show-initial-content" so that it starts off with the content shown, rather than hidden 

*/



/* 
showhide USAGE:
<a class="small-show-button" href="#targetid" onclick="showhide('targetid', this); return false;">show/hide this content</a>

Note that the 2nd parameter "this" is needed if you want to swap this element's class for the expand/contract icon image. If you don't want to swap the icon image, just leave out the class in the <a> tag and leave out the 2nd parameter when calling showhide()
*/
function showhide(targetelementid, currentelement) { 

   thecontent = document.getElementById(targetelementid); 

   if (thecontent.className.match("show-initial-content")) { 
      thecontent.className = thecontent.className.replace("show-initial-content", "hide-content"); 
   }
   else if (thecontent.className.match("hide-initial-content")) { 
      thecontent.className = thecontent.className.replace("hide-initial-content", "show-content"); 
   }   
   else if (thecontent.className.match("show-content")) { 
      thecontent.className = thecontent.className.replace("show-content", "hide-content"); 
   }
   else if (thecontent.className.match("hide-content")) { 
      thecontent.className = thecontent.className.replace("hide-content", "show-content"); 
   }

	if (typeof(currentelement) != 'undefined') {	/*if the 2nd function parameter (a "this" reference to the current element) is defined and thus was passed */

	   /* we check to see if there is a expand/contract icon image class attached to this element, if so we swap the state by changing the class */
	   if (currentelement.className.match("small-show-button")) {
	   	  currentelement.className = currentelement.className.replace("small-show-button", "small-hide-button");
	   }
	   else if (currentelement.className.match("small-show-initial-button")) {
	   	  currentelement.className = currentelement.className.replace("small-show-initial-button", "small-hide-button");       
       }
	   else if (currentelement.className.match("small-hide-button")) {
	   	  currentelement.className = currentelement.className.replace("small-hide-button", "small-show-button");
	   }
	   else if (currentelement.className.match("small-hide-initial-button")) {
	   	  currentelement.className = currentelement.className.replace("small-hide-initial-button", "small-show-button");
	   }	   
	   else if (currentelement.className.match("show-button")) {
	   	  currentelement.className = currentelement.className.replace("show-button", "hide-button");
	   }
	   else if (currentelement.className.match("hide-button")) {
	   	  currentelement.className = currentelement.className.replace("hide-button", "show-button");
	   }
	   else if (currentelement.className.match("hide-initial-button")) {
	   	  currentelement.className = currentelement.className.replace("hide-initial-button", "show-button");
	   }	   
	}
} 



/*
function showhidetogglebutton(elementidbase) { 

   //thebutton = document.getElementById(elementid); 
   var showButton = document.getElementById("show-" + elementidbase); 
   var hideButton = document.getElementById("hide-" + elementidbase); 

   if (showButton.className.match("toggle-all-show")) {
	  showButton.className = showButton.className.replace("toggle-all-show", "toggle-all-hide");	
	  hideButton.className = hideButton.className.replace("toggle-all-hide", "toggle-all-show");	
   }
   else if (hideButton.className.match("toggle-all-show")) {
	  hideButton.className = hideButton.className.replace("toggle-all-show", "toggle-all-hide");	
	  showButton.className = showButton.className.replace("toggle-all-hide", "toggle-all-show");	
   }     
}
*/



/* getElementsByClass by Dustin Diaz
Note that for IE5 compatibility (it doesn't support the "*" wildcard for elements), you need to specify the tag, e.g.
getElementsByClass("show-button", document, "a")
*/
function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp('(^|\\s)'+searchClass+'(\\s|$)');
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}






/* This function is used to swap the state of any toggle-all-hide and toggle-all-show buttons on this page */
function toggleShowHideAll() {

	var toggleAllShowElements = getElementsByClass("toggle-all-show", document, "a").concat( getElementsByClass("toggle-all-initial-show", document, "a") );	
	var toggleAllHideElements = getElementsByClass("toggle-all-hide", document, "a").concat( getElementsByClass("toggle-all-initial-hide", document, "a") );	
		
	for (var x=0; x != toggleAllShowElements.length; x++) {
		var toggleAllShowElement = toggleAllShowElements[x];
				
		if (! toggleAllShowElement) { return; }
		toggleAllShowElement.className = toggleAllShowElement.className.replace("toggle-all-show", "toggle-all-hide");
		toggleAllShowElement.className = toggleAllShowElement.className.replace("toggle-all-initial-show", "toggle-all-hide");		
	}
	
	for (var x=0; x != toggleAllHideElements.length; x++) {
		var toggleAllHideElement = toggleAllHideElements[x];
				
		if (! toggleAllHideElement) { return; }
		toggleAllHideElement.className = toggleAllHideElement.className.replace("toggle-all-hide", "toggle-all-show");
		toggleAllHideElement.className = toggleAllHideElement.className.replace("toggle-all-initial-hide", "toggle-all-show");		
	}			
}



/* This function is mostly identical to toggleShowHideAll, except it only executes as part of the "on page load" */
function toggleShowHideAllOnPageLoad() {

	var toggleAllShowElements = getElementsByClass("toggle-all-show", document, "a");	
	var toggleAllHideElements = getElementsByClass("toggle-all-hide", document, "a");	
		
	for (var x=0; x != toggleAllShowElements.length; x++) {
		var toggleAllShowElement = toggleAllShowElements[x];
				
		if (! toggleAllShowElement) { return; }
		toggleAllShowElement.className = toggleAllShowElement.className.replace("toggle-all-show", "toggle-all-hide");
	}
	
	for (var x=0; x != toggleAllHideElements.length; x++) {
		var toggleAllHideElement = toggleAllHideElements[x];
				
		if (! toggleAllHideElement) { return; }
		toggleAllHideElement.className = toggleAllHideElement.className.replace("toggle-all-hide", "toggle-all-show");
	}			
}







/* this function looks for all elements with class="show-content" and changes it to "hide-content" 
*/
function hideAllShownElements() {

	toggleShowHideAll();	// swap the state of any "show/hide all" buttons
	
	var shownElements = getElementsByClass("show-content", document, "div").concat( getElementsByClass("show-initial-content", document, "div") );
	
	for (var x=0; x != shownElements.length; x++) {
		var shownElement = shownElements[x];
				
		if (! shownElement) { return; }
		shownElement.className = shownElement.className.replace("show-content", "hide-content");
		shownElement.className = shownElement.className.replace("show-initial-content", "hide-content"); 
	}
	
	
	/* below, we attempt to swap states of expand/contract icon images 
	Firstly, we swap the large icon images
	*/	
	var toggleButtonElements = getElementsByClass("hide-button", document, "a");	
	for (var x=0; x != toggleButtonElements.length; x++) {
		var toggleButtonElement = toggleButtonElements[x];
				
		if (! toggleButtonElement) { return; }
		toggleButtonElement.className = toggleButtonElement.className.replace("hide-button", "show-button");
	}

	/* Firstly, we swap the large icon images	*/	
	var toggleButtonElements = getElementsByClass("hide-initial-button", document, "a");	
	for (var x=0; x != toggleButtonElements.length; x++) {
		var toggleButtonElement = toggleButtonElements[x];
				
		if (! toggleButtonElement) { return; }
		toggleButtonElement.className = toggleButtonElement.className.replace("hide-initial-button", "show-button");
	}



	/* now we attempt to swap the small icon images */
	var toggleSmallButtonElements = getElementsByClass("small-hide-button", document, "a");	
	for (var x=0; x != toggleSmallButtonElements.length; x++) {
		var toggleSmallButtonElement = toggleSmallButtonElements[x];
				
		if (! toggleSmallButtonElement) { return; }
		toggleSmallButtonElement.className = toggleSmallButtonElement.className.replace("small-hide-button", "small-show-button");
	}

	/* now we attempt to swap the small icon images */
	var toggleSmallButtonElements = getElementsByClass("small-hide-initial-button", document, "a");	
	for (var x=0; x != toggleSmallButtonElements.length; x++) {
		var toggleSmallButtonElement = toggleSmallButtonElements[x];
				
		if (! toggleSmallButtonElement) { return; }
		toggleSmallButtonElement.className = toggleSmallButtonElement.className.replace("small-hide-initial-button", "small-show-button");
	}

	
}





/* this function is mostly identical to hideAllShownElements, except it gets executed during page onload
*/
function hideAllShownElementsOnPageLoad() {

	toggleShowHideAllOnPageLoad();	// swap the state of any "show/hide all" buttons
	
	var shownElements = getElementsByClass("show-content", document, "div");
	
	for (var x=0; x != shownElements.length; x++) {
		var shownElement = shownElements[x];
				
		if (! shownElement) { return; }
		shownElement.className = shownElement.className.replace("show-content", "hide-content");
	}
	
	
	/* below, we attempt to swap states of expand/contract icon images 
	Firstly, we swap the large icon images
	*/	
	var toggleButtonElements = getElementsByClass("hide-button", document, "a");	
	for (var x=0; x != toggleButtonElements.length; x++) {
		var toggleButtonElement = toggleButtonElements[x];
				
		if (! toggleButtonElement) { return; }
		toggleButtonElement.className = toggleButtonElement.className.replace("hide-button", "show-button");
	}	

	/* now we attempt to swap the small icon images */
	var toggleSmallButtonElements = getElementsByClass("small-hide-button", document, "a");	
	for (var x=0; x != toggleSmallButtonElements.length; x++) {
		var toggleSmallButtonElement = toggleSmallButtonElements[x];
				
		if (! toggleSmallButtonElement) { return; }
		toggleSmallButtonElement.className = toggleSmallButtonElement.className.replace("small-hide-button", "small-show-button");
	}
}








/* this function looks for all elements with class="hide-content" and changes it to "show-content" 
*/
function showAllHiddenElements() {
	toggleShowHideAll();	// swap the state of any "show/hide all" buttons

	var hiddenElements = getElementsByClass("hide-content", document, "div").concat( getElementsByClass("hide-initial-content", document, "div") );

	
	for (var x=0; x != hiddenElements.length; x++) {
		var hiddenElement = hiddenElements[x];
				
		if (! hiddenElement) { return; }
		hiddenElement.className = hiddenElement.className.replace("hide-content", "show-content");
		hiddenElement.className = hiddenElement.className.replace("hide-initial-content", "show-content");         
	}	
	
	/* below, we attempt to swap states of expand/contract icon images 
	Firstly, we swap the large icon images
	*/
	
	var toggleButtonElements = getElementsByClass("show-button", document, "a");	
	for (var x=0; x != toggleButtonElements.length; x++) {
		var toggleButtonElement = toggleButtonElements[x];
				
		if (! toggleButtonElement) { return; }
		toggleButtonElement.className = toggleButtonElement.className.replace("show-button", "hide-button");
	}	

	/* now we attempt to swap the small icon images */
	var toggleSmallButtonElements = getElementsByClass("small-show-button", document, "a");	
	for (var x=0; x != toggleSmallButtonElements.length; x++) {
		var toggleSmallButtonElement = toggleSmallButtonElements[x];
				
		if (! toggleSmallButtonElement) { return; }
		toggleSmallButtonElement.className = toggleSmallButtonElement.className.replace("small-show-button", "small-hide-button");
	}	
    
	/* now we attempt to swap the small icon images */
	var toggleSmallButtonElements = getElementsByClass("small-show-initial-button", document, "a");	
	for (var x=0; x != toggleSmallButtonElements.length; x++) {
		var toggleSmallButtonElement = toggleSmallButtonElements[x];
				
		if (! toggleSmallButtonElement) { return; }
		toggleSmallButtonElement.className = toggleSmallButtonElement.className.replace("small-show-initial-button", "small-hide-button");
	}	    
			
}





/* extract values for variables specified in URL query string */
function getQueryVariable(variable) {
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	
	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
		if (pair[0] == variable) {
			return pair[1];
		}
	}

} 




/* 
When page loads we want to hide all shown elements, i.e. elements with class="show-content", and we also set the correct icon images and states for show/hide buttons

We show content by default in case user has Javascript turned off. 
If JS is on, then content is forced to hide, until user activates a expand/contract content button 

The only exception is if URL query string contains ?donothidesections=true in which case we don't hide all sections upon page load
Example usage: http://staff-dev.sl.nsw.gov.au/elsservicedesk/tips/email.cfm?donothidesections=true#what-is-a-hyperlink
*/

var doNotHideSections = getQueryVariable("donothidesections");
if (doNotHideSections != "true") { 
	addLoadEvent(hideAllShownElementsOnPageLoad);
}		



// end -->