function XmlHttp(){var a;try{a=new XMLHttpRequest()}catch(b){try{a=new ActiveXObject("Msxml2.XMLHTTP")}catch(b){try{a=new ActiveXObject("Microsoft.XMLHTTP")}catch(b){MessageBox("Your browser does not support AJAX!")}}}return a}

function Loader (basedir)
{
	this.basedir = basedir;
	this.pages = Array();
}
Loader.prototype.pages = false;
Loader.prototype.basedir = false;
Loader.prototype.nav = false;
Loader.prototype.showFirst = function () { this.pages[0].show(); }
Loader.prototype.get = function (addr) {
	for(var i=0; i < this.pages.length; i++)
		if(this.pages[i].addr == addr)
			return this.pages[i];
	return false;
}
Loader.prototype.addPage = function (title, content)
{
	this.pages.push(new Page(title,this.basedir+content));
}
Loader.prototype.setNav = function (navid)
{
	this.nav = document.getElementById(navid);
	for(var i=0; i < this.pages.length; i++)
	{
		var li = document.createElement('li');
		var a = document.createElement('a');
		a.appendChild(document.createTextNode(this.pages[i].title));
		a.page = this.pages[i];
		a.onclick = function () { this.page.show(); };
		a.href = '#'+escape(this.pages[i].addr);
		li.appendChild(a);
		this.nav.appendChild(li);
	}
}

function Page(title,content)
{
	this.title = title;
	this.content = content;
	this.addr = '';
	for(var i=0; i < title.length; i++)
		if(title.charCodeAt(i) < 128)
			this.addr += title.charAt(i);
}
Page.prototype.title = false;
Page.prototype.addr = false;
Page.prototype.content = false;
Page.prototype.show = function ()
{
	document.getElementById('content').innerHTML = 'Loading';
	var xmlhttp = XmlHttp();
	xmlhttp.onreadystatechange = function ()
	{
		if (xmlhttp.readyState==4)
			if(xmlhttp.status==200)
			{
				document.getElementById('content').innerHTML = xmlhttp.responseText;
			}
			else
			{
				document.getElementById('content').innerHTML = '<div class="error">Error '+xmlhttp.status+'</div>';
			}
	};
	xmlhttp.open("GET",this.content,true);
	xmlhttp.send(null);
}
