/*
	Written By James Jackson for Live Technologies Ltd © 2009 all rghts reserved


Each function is called using the addLoadFunction using the following syntax
	
	<!--  Begin miniScript calls   -->
	<script type="text/javascript">
	var titleHolder = '{PAGEHEADING}';
	addLoadEvent(brimages);
	addLoadEvent(classify);
	</script>
	<!--  End miniScript calls     -->
	
NB: When using functions that require the {PAGEHEADING} php include it is necessary to declare this 
as shown on the second line of the code

*/


//Used on gallery page to split the images accross 2 rows

function brimages(){
	
	var images = document.getElementById("gall").getElementsByTagName("a");
	
	var amount = parseInt((images.length / 2) + 0.5);
	
	images[amount].innerHTML += "<br>"; 
	
}
	  
//This function applies a different class to each nav link and highlights the current one. Designed for Ty'n Rhos

function classify(){	

	var anchors  = document.getElementById("nav").getElementsByTagName("a");
	
	var title = title;
	
	for(var i=0, n=anchors.length; i<n; ++i) {
		
		anchors[i].className += " nav" + (i +1);
		
	}


	for (var i = 0, n = anchors.length; i < n; ++ i) {
		
		if ((anchors[i].innerHTML.replace(/[^a-z]/ig, "")).toLowerCase() == titleHolder ) {
			
			anchors[i].className = 'cur' + (i+1);
			
			break;
			
		}
		
	}
	
}


//Using the {PAGEHEADING} Syntax this function adds a cur class to the current page, NB
//var titleHolder = '{PAGEHEADING}'; must be used!!

function classifyByPageHeading(){
	
	var anchors  = document.getElementsByTagName("a");
	
		for (var i = 0, n = anchors.length; i < n; ++ i) {
			
			if ((anchors[i].innerHTML.replace(/[^a-z]/ig, "")).toLowerCase() == titleHolder ) {
				
			anchors[i].className = 'cur';
			
			break;
			
		}
		
	}
	
}


//Using the current pages uri this function adds a cur class to the current page
//A global variable of where must be set to state the id of the navs containing div.

function classifyByUri(){

	var anchors  = document.getElementById(where).getElementsByTagName("a");
	
	var uri = encodeURI(window.location.href).toLowerCase();
	
	for(var i=0, n=anchors.length; i<n; ++i) {
		
		if(uri==encodeURI(anchors[i].href).toLowerCase()) {
			
			anchors[i].className = 'cur';
			
			break;
			
		}
		
	}
	
}







function addLoadEvent(func) {
	
  var oldonload = window.onload;
  
  if (typeof window.onload != 'function') {
	  
    window.onload = func;
	
  } else {
	  
    window.onload = function() {
		
      oldonload();
	  
      func();
	  
    }
	
  }
  
}



//Form Validation Code


