//highlights current page on left menu

var url = String(window.location);;

function iamhere() {
	
  	for(var i=0; i < id_list.length; i++)
  	{
    	var id = id_list[i];	
		var search_url = url.match(id);	
	if ((search_url == id))
    		{
				var getNode = document.getElementById(search_url);
					getNode.className = "current";			
			}
	
	}

}

//hides sections of a page according to div id and shows the relevant section when the appropriate link is clicked

var divs2hide = new Array("section1", "section2", "section3", "section4", "section5", "section6", "section7"); 
//this is a global array as it is used in the showAll function too

function hideDivs(exempt) //hides all the section divs except for the exempt ones listed at the bottom of this file in the onload function
{
  if (!document.getElementsByTagName) return null;
  if (!exempt) exempt = "";
  var divs = document.getElementsByTagName("div"); 
  for(var x=0; x < divs.length; x++) //iterate through the div tags in the document
  {
  	var div = divs[x];
  	var id = div.id;
	  for(var i=0; i < divs2hide.length; i++) //iterate through the array divs2hide above
	  {
		var hid_id = document.getElementById(divs2hide[i]);
		if (!hid_id) {
		  	hid_id = "";
		}
		else if (hid_id.id != exempt) { //if the divs are not exempt, hide them using the hidden style defined in the style sheet
			hid_id.className = "hidden";
		}
	  } 
   }
}


function showSection(sectionID) {
	var section_div = document.getElementById(sectionID); //get id of the section from onload function below and then find it in the document
	if (!section_div) return null;
  	if (!document.getElementsByTagName) return null;
  	var server = window.location.href;
	
	if (server.indexOf(sectionID) !=-1) {
			
			section_div.className = "visible";
			
			hideDivs(sectionID);
			
	}
	
	var anchors = document.getElementsByTagName("a"); //get all a tags
	for (var k=0; k < anchors.length; k++) //iterate through all a tags in document
	{
		var a = anchors[k];
		var href = a.href;
		var name = (sectionID +"_link"); //this is the class name of all a tags that link to the div sections above
		
			
		if ((a.className.indexOf(sectionID) != -1)) { //find the sectionID in the class name of the a tags in the document e.g. <a class="section1_link">
			
			if ((!a.id) && (a.className == name)) { //if the a tag has no existing id and if the class matches the sectionID_link name, then set a new ID
				var newID = (sectionID+"_link");
				a.setAttribute("id", newID); //this new ID enables the onclick behaviour
				var get_link = document.getElementById(newID);
					get_link.onclick = function () {
					section_div.className = "visible";//on clicking the a tag, the relevant sections are hidden/shown
					hideDivs(sectionID);
					}
				}
				else {
				return null;
				}
				a.setAttribute("id", null);	
			
		}

	}

}


function showAll(id) { //this allows for all sections to be displayed at once
 	var show_link = document.getElementById(id);
	if (!show_link) return null;
		show_link.onclick = function() {
			for(var j=0; j < divs2hide.length; j++)
			  {
				var div_id = divs2hide[j];
				var show_divs = document.getElementById(div_id);				
					show_divs.className = "visible";
			  }
		}

}


//random image rotator script

<!-- Begin
var randomIMG = 0;
var DoIt = 0;
images = new Array("blank.jpg", "aminita_fungus.jpg", "agapanthisTS.jpg", "avicennia_stem.jpg", "banksia.jpg", "banksia_bloom.jpg", "eucalypt_flower.jpg", "geckoWA.jpg", "hoverfly.jpg", "mantis.jpg", "moss.jpg", "red_coral.jpg", "red_mushrooms.jpg", "starfish.jpg", "swampWA.jpg"); 

var img_loc = "images/rotating_photos/";

function RandomPics() {
  	
	var imgnum = images.length - 1;
	do {
		var randnum = Math.random();
		randomIMG = Math.round((imgnum - 1) * randnum) + 1;
		}
	while (randomIMG == DoIt);
	DoIt = randomIMG;
	document.ImageHolder.src = img_loc+(images[DoIt]);
}


window.onload = function()
{	
  RandomPics();
  hideDivs("section1");	//id of the div to appear onload
  showSection("section1"); 
  showSection("section2"); 
  showSection("section3"); 
  showSection("section4"); 
  showSection("section5");
  showSection("section6");
  showSection("section7");
  showAll("view_all_link");
  iamhere(); 
 }