function globalNavBehaviour() {
	var navRoot = document.getElementById("global_nav");
	for (var i=0, nodesLength=navRoot.childNodes.length; i<nodesLength; i++) { 
		node = navRoot.childNodes[i]; 
		if (node.nodeName=="LI") { 
			node.onmouseover=function() { 
				this.className+=" over"; 
			}
			node.onmouseout=function() { 
				this.className=this.className.replace(" over", ""); 
			}
		}
	}
}

function businessNavBehaviour() {
	var navRoot = document.getElementById("business_nav");
	if (navRoot!=null) {
		for (var i=0, nodesLength=navRoot.childNodes.length; i<nodesLength; i++) { 
			node = navRoot.childNodes[i]; 
			if (node.nodeName=="LI") { 
				node.onmouseover=function() { 
					this.className+=" over"; 
	
				}
				node.onmouseout=function() { 
					this.className=this.className.replace(" over", " "); 
				}
			}
		}
	}
}

function addMainSearchBehaviour() {
	var main_search_input = document.getElementById('main_search_input');

	main_search_input.onfocus = function() { 
		if (this.value=='Search') {
			this.value='';
		}
	}
	main_search_input.onblur = function() { 
		if (this.value=='') {
			this.value='Search';
		}
	}
}

function replaceFonts() {
	Cufon.now();
	Cufon.replace('.maincolumn .content h2');
	Cufon.replace('div.widget h5');
	Cufon.replace('#gnavabout a, #gnavnews a, #gnavourbusinesses a, #gnavrecruitment a', {hover: 'true'});
	Cufon.replace('div.colum.width4.services h3');
	Cufon.replace('ul#business_nav li ul li a', {hover: 'true'});
	Cufon.replace('div#navlevel3 a', {hover: 'true'});
}

function markFirstLastLi() {

	var count = 0;
	var liList, ulTag;
	var ulList = document.getElementsByTagName("ul");
	for (var i=0, ulListLength=ulList.length; i < ulListLength; i++) {
		ulTag = ulList[i];
		try{
			liList = ulTag.getElementsByTagName("li");
			if(liList[0]){
				liList[0].className+=" first";
				if(liList[1]){
					liList[liList.length - 1].className+=" last";
				}
			}
			count++;
		}catch(exception){

		}
	}

}

function mailUrl(subject) {
    u = window.location;
    m = subject;
    title = document.title.replace("& ", "&amp; ");
    
    // the following expression must be all on one line
    window.location = "mailto:?subject="+m+"&body="+escape(document.title)+" "+u;
}

function init() {
	markFirstLastLi();
	globalNavBehaviour();
	businessNavBehaviour();
	addMainSearchBehaviour();
	DD_belatedPNG.fix('#global_nav li ul, #business_nav li ul');
	replaceFonts();
}
