function getRequest() {
	var request = false;
	if (typeof(XMLHttpRequest) != 'undefined') {
		request = new XMLHttpRequest();
	}
	if (!request) {
		try {
			request  = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				request  = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {
				request  = false;
			}
		}
	}
	return request;
}

function setAnchor(anc) {
	var arr = new String(document.location).split("#");
	document.location = arr[0] + "#" + anc;
	/*
	document.title = anc;
	var anchor = document.createElement('a');
	anchor.setAttribute('name', anc);
	if (!anchor) anchor = document.createElement('<a name="'+anc+'"></a>');
	document.body.insertBefore(anchor,document.body.firstChild);
	*/
}

function getAnchor() {
	var arr = new String(document.location).split("#");
	if (arr.length > 1) return arr[1];
	else return "";
}

function loadContent(url) {
	var request = getRequest();
	if (request) {
		loading = true;
		request.open('GET', 'folder.php?folder='+url, true);
		request.onreadystatechange = function () {
			if (request.readyState == 4) {
				loading = false;
				var node = document.getElementById("container");
				node.innerHTML = request.responseText;
			}
		}
		request.send(null);
	}
}

function jsnavigate(url) {
	loadContent(url);
	flashPath = url;
	flashProxy.call('jsnavigate', flashPath, flashFocus);
	setAnchor(url);
}

function asnavigate(url) {
	loadContent(url);
	flashPath = url;
	/*
	setAnchor(url);
	*/
}

function jsfocus(url) {
	flashFocus = url;
	flashProxy.call('jsnavigate', flashPath, flashFocus);
}

function restoreLink() {
	jsnavigate(getAnchor());
}

function watchLocation() {
	if (loading) return;
	var anc = getAnchor();
	if (typeof(savedAnchor) == 'undefined') savedAnchor = anc;
	if (savedAnchor != anc) {
		jsnavigate(anc);
		savedAnchor = anc;
	}
}

function plainVersion() {
	document.location = "plain.php?folder="+getAnchor();
}



var uid = new Date().getTime();
var flashProxy = new FlashProxy(uid, 'JavaScriptFlashGateway.swf');
flashPath  = "root";
flashFocus = "root";
loading = false;
if (setInterval) setInterval(watchLocation, 200);
