window.onload=function() {
	menuFix();
	hideLayers();
	showStoryButtons();
}

// Operates the top nav drop downs
function menuFix() {
	var sfEls = document.getElementById("topnav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
		this.className+=(this.className.length>0? " ": "") + "over";
		}
		// event added to keep menu items from disappearing
		sfEls[i].onMouseDown=function() {
		this.className+=(this.className.length>0? " ": "") + "over";
		}
		// event added to keep menu items from disappearing
		sfEls[i].onMouseUp=function() {
		this.className+=(this.className.length>0? " ": "") + "over";
		}
		sfEls[i].onmouseout=function() {
		this.className=this.className.replace(new RegExp("( ?|^)over\\b"), "");
		}
	}
}

//Used to operate highlight boxes on Schools, Programmes and Services pages
function toggleLayer(aLink) {
	var elem, vis, head;
	for(var i=0; i<aLink.parentNode.parentNode.childNodes.length; i++)
	{
		if(aLink.parentNode.parentNode.childNodes[i].className != null)
		{
			if(aLink.parentNode.parentNode.childNodes[i].className == 'content')
			{
				elem = aLink.parentNode.parentNode.childNodes[i];
				vis = elem.style;
				if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
					vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
				vis.display = (vis.display==''||vis.display=='block')?'none':'block';
			}
		}
	}			
	elem = aLink.parentNode.parentNode.parentNode;
	head = aLink.parentNode;
	if(head.className == 'heading_curve')
		head.className = 'heading_curve_selected';
	else
		head.className = 'heading_curve';
}
function showStoryButtons() {
	var elem1, elem2, cont, vis;
	elem1 = document.getElementsByName( 'prevButton' );
	elem2 = document.getElementsByName( 'nextButton' );	
	for (i in elem1)
	{
		cont = elem1[i];
		vis = cont.style;	
		if(vis != undefined)
			vis.display = 'block';
	}
	for (j in elem2)
	{
		cont = elem2[j];
		vis = cont.style;	
		if(vis != undefined)
			vis.display = 'block';
	}
	
}
function hideLayers() {
	var elem, cont, vis, head;
	if( document.getElementById ) // this is the way the standards work
		elem = document.getElementById( 'boxedinfo_wrapper' );
	else if( document.all ) // this is the way old msie versions work
		elem = document.all['boxedinfo_wrapper'];
	else if( document.layers ) // this is the way nn4 works
		elem = document.layers['boxedinfo_wrapper'];
	if (undefined != elem)
	{
	for(var j=0; j<elem.childNodes.length; j++)
	{
		vis = null;
		for(var i=0; i<elem.childNodes[j].childNodes.length; i++)
		{
			if(elem.childNodes[j].childNodes[i].className != null)
			{
				if(elem.childNodes[j].childNodes[i].className == 'content')
				{
					cont = elem.childNodes[j].childNodes[i];
					vis = cont.style;
					if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
						vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
					vis.display = (vis.display==''||vis.display=='block')?'none':'block';
				}
				else if(elem.childNodes[j].childNodes[i].className == 'heading_curve_selected')
				{
					head = elem.childNodes[j].childNodes[i];
					head.className = 'heading_curve';
				}
			}
		}				
	}	
	}		
}

