var bustcachevar = 1;
var bustcacheparameter = "";
var loadstatustext = "<img src='images/loading.gif' /> Requesting content...";
var currentContainerId = null;
var myhist = new Array();

function loadpage(page_request, containerId)
{
	if (page_request.readyState != 4)
		return;
	if (!containerId)
	{
		if (page_request.status == 200)
		{
			eval(page_request.responseText);
		}
	}
	else
	{
		if (page_request.status == 200 ||
			window.location.href.indexOf("http") == -1)
		{
			document.getElementById("lobby").innerHTML = '<div id="swfobject" style="margin: 0px; padding: 0px; width: 650px; height: 351px;">' + page_request.responseText + '</div>';
			if (window.currentImg)
			{
				ajaxpage(window.currentImg + '.js', null);
			}
		}
	}
}

function ajaxpage(url, containerId)
{
	currentContainerId = containerId;

	var page_request = false;

	// if Mozilla, Safari etc
	if (window.XMLHttpRequest)
	{
		page_request = new XMLHttpRequest();
	}
	// if IE
	else if (window.ActiveXObject)
	{
		try
		{
			page_request = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e)
		{
			try
			{
				page_request = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {}
		}
	}
	else
		return false;

	// show busy loading image and text
	if (typeof document.getElementById("lobby") != "undefined")
	{
	}

	// function to process response once it arrives
	page_request.onreadystatechange = function()
	{
		loadpage(page_request, currentContainerId);
	}

	// bust potential caching of external pages after initial request ?
	// (1=yes, 0=no)
	if (bustcachevar)
		bustcacheparameter = (url.indexOf("?")!=-1) ? "&" + new Date().getTime() : "?" + new Date().getTime();

	// send off the request to the server
	page_request.open('GET', url+bustcacheparameter, true)
	try
	{
		page_request.send(null);
	}
	catch (e) {}
}

function point(img)
{
//	myhist.push(img);
	var c = document.getElementById("lobby");
	if (typeof c == "undefined" || !c)
	{
		var d = document.createElement("div");
		d.setAttribute("id", "lobby");
		document.getElementById("lobby-container").appendChild(d);
	}

	document.getElementById("lobby").innerHTML = '<div id="swfobject" style="margin: 0px; padding: 0px; width: 650px; height: 351px;">' + loadstatustext + '</div>';
	window.currentImg = img;
	ajaxpage(window.currentImg + '.html', 'swfobject');
}

function histpoint()
{
	if (myhist.length <= 1)
		return;
	myhist.pop();
	point(myhist.pop());
}
