/** Javascript code for Tonbridge School **/

/* Initialise variables */
if (document.getElementById) {
	/* Onmouseover */
	var imageDir = "/images/";
	var loaded = 0;
}

/* This will be called once the page has loaded */
function setup() {
	if (!document.getElementById || !document.getElementById('location'))
		return;
	
	/* Shift down 2 + 2 */
	var top = document.getElementById('location').offsetTop + 4;
	document.getElementById('location_box').style.top = top;
	if (document.getElementById('location_box').style.top == '') {
		document.getElementById('location_box').style.top = '' + top + 'px;';
		
	}
	
	loaded = 1;
}



/** Location box code **/
// Purpose: Provide functions for the jump boxes on the site; the location bar

function location_open(level) {
	if (!document.getElementById || !window.locationBox || loaded == 0)
		return;
	
	if (!locationBox[level] || !locationBox[level].text) {
		// This level doesnt exist. Lets make sure the box is shut...
		location_close();
		return;
	}
	
	// Load data into the box
	var i;
	var output = '';
	for (i=0; i<locationBox[level].text.length; i++) {
		if (i == locationBox[level].selected) {
			output += '<li class="selected"><span>'+locationBox[level].text[i]+'</span></li>';
		} else {
			output += '<li><a href="'+locationBox[level].url[i]+'">'+locationBox[level].text[i]+'</a></li>';
		}
	}
	document.getElementById('location_box').innerHTML = '<ul>'+output+'</ul>';
	
	// Show the box
	var left = document.getElementById('location_level'+level).offsetLeft;
	document.getElementById('location_box').style.left = '';
	document.getElementById('location_box').style.left = left;
	if (document.getElementById('location_box').style.left == '') {
		document.getElementById('location_box').style.left = '' + left + 'px;';
	
	}

	document.getElementById('location_box').style.visibility = 'visible';
}

function location_in() {
	if (!document.getElementById || loaded == 0)
		return;
	
	location_current_in = 1
}

function location_out() {
	if (!document.getElementById || loaded == 0)
		return;
	
	var location_close_timeout = setTimeout('location_close();', 100);
}

function location_close() {
	if (!document.getElementById || loaded == 0)
		return;
	
	document.getElementById('location_box').style.visibility = 'hidden';
	location_current_in = 0;
}
