
function display_text(htmltext, target){
	var x = htmltext.indexOf("<body");
	x = htmltext.indexOf(">", x);    
	var y = htmltext.lastIndexOf("</body>"); 
	htmltext = htmltext.slice(x + 1, y);
	if (typeof target == "string") target = document.getElementById(target);
	target.innerHTML =  htmltext;
}

var current_panel = null;

function changeback(e, colour){

var re = /pCurrent/g;
	if (!e.className.match(re)){
		e.style.backgroundColor=colour;
	}
}

function changepanel (object, bgcol, fgcol){
	var re = /Text/g;
	if (object.id.match(re)){
		var tre = /Text/g;	
		var url = "text.php?t=";
		var first_id = 'Text1';
	} 
	var re = /Job/g;
	if (object.id.match(re)){
		var tre = /Job/g;	
		var url = "xjob.php?j=";
		var first_id = 'Job1';	
	}
	var re = /Contact/g;
	if (object.id.match(re)){ 
		var tre = /Contact/g;	
		var url = "text.php?c=";
	}
	
	if (typeof current_panel == 'string') current_panel = document.getElementById(current_panel);
	current_panel.className = 'Panel CentrePanel pVisited';
	current_panel.style.backgroundColor = "#ffffff";

	current_panel = object;
	object.className = 'Panel CentrePanel pCurrent';
	object.style.backgroundColor = bgcol;

	var text_id = object.id.replace(tre, "");
	url = url + text_id;

	var target = document.getElementById("RightPanelContents");
	target.innerHTML =  '<h1 class="loading">LOADING...</h1>';

	var request = HTTP.newRequest();
	request.onreadystatechange = function() {
		if (request.readyState==4) { 
			if (request.status == 200){
				display_text(request.responseText, target);
			}
		}
	}
	
	request.open("GET", url, true);
	request.setRequestHeader("User-Agent", "XMLHttpRequest");
	request.send(null);	
	


	return(false);
}

var panel_count = 0;
var top_panel = 0;
var num_panels = 4;

function PanelUp(ptype){
	document.getElementById('PanelDown').style.position = 'relative';
	document.getElementById('PanelDown').style.top = 0;

	
	last_panel = top_panel + num_panels - 1;
	var lastid = parray[last_panel];
	top_panel--;
	var firstid = parray[top_panel];

	document.getElementById(lastid).style.position = 'absolute';
	document.getElementById(lastid).style.top = '-1000px';

	document.getElementById(firstid).style.position = 'relative';
	document.getElementById(firstid).style.top = '0';

	var more = parray.length - last_panel;	
	document.getElementById('PanelDown').innerHTML = more + ' MORE BELOW';
	document.getElementById('PanelUp').innerHTML = top_panel + ' MORE ABOVE';

	if (top_panel == 0){
		document.getElementById('PanelUp').style.position = 'absolute';
		document.getElementById('PanelUp').style.top = '-1000px';	
	}
}


function PanelDown(panels, ptype){
	panel_count = panels;
	document.getElementById('PanelUp').style.position = 'relative';
	document.getElementById('PanelUp').style.top = 0;
	var topid = parray[top_panel];
	next_panel = top_panel + num_panels;
	var nextid = parray[next_panel];
	top_panel++;

	document.getElementById(topid).style.position = 'absolute';
	document.getElementById(topid).style.top = '-1000px';

	document.getElementById(nextid).style.position = 'relative';
	document.getElementById(nextid).style.top = '0';

	var more = parray.length - next_panel - 1;	
	document.getElementById('PanelDown').innerHTML = more + ' MORE BELOW';
	document.getElementById('PanelUp').innerHTML = top_panel + ' MORE ABOVE';

	if (next_panel == parray.length - 1){
		document.getElementById('PanelDown').style.position = 'absolute';
		document.getElementById('PanelDown').style.top = '-1000px';	
	}



}
