var loaderObj;
var xmlObj;
var opc=10;
var t;
var move=0; var Fx; var Fy; var mC;
function mainRequest(link) {
	loaderObj = document.createElement("div");
	loaderObj.className = "loader";
	loaderObj.innerHTML = "Requesting page...";
	loaderObj.setAttribute("valign", "center");
	loaderObj.setAttribute("id", "loader");
	document.body.appendChild(loaderObj);
	if (window.XMLHttpRequest) {
  	xmlObj=new XMLHttpRequest();
  }
	else if (window.ActiveXObject) {
  	xmlObj=new ActiveXObject("Microsoft.XMLHTTP")
  }
	if (!xmlObj) {
		alert("Your browser does not support Ajax. This website is based on Ajax." + '\n' + "Please consider upgrading your browser. We are sorry for the inconvenience, an Ajax-free version is on its way");
		return;
	}
	xmlObj.onreadystatechange = stateGotChanged;
	link += "?rand=" + Math.random();
	xmlObj.open("GET", link, true);
	xmlObj.send(null);
}
function stateGotChanged() {
	if (xmlObj.readyState==4 || xmlObj.readyState=="complete") {
		while(loaderObj=document.getElementById('loader')) {
			document.body.removeChild(loaderObj);
		}
		document.getElementById('container').innerHTML = xmlObj.responseText;
	}
}
function example(fileName) {
	window.open("examples/" + fileName, "_blank", "channelmode=no, directories=yes, fullscreen=no, height=400, location=yes, menubar=yes, resizable=no, scrollbars=no, status=yes, titlebar=yes, toolbar=yes, width=500");
}
function download(file) {
	if (window.XMLHttpRequest) {
  	xmlObj=new XMLHttpRequest();
  }
	else if (window.ActiveXObject) {
  	xmlObj=new ActiveXObject("Microsoft.XMLHTTP")
  }
	if (!xmlObj) {
		alert("Your browser does not support Ajax. This website is based on Ajax." + '\n' + "Please consider upgrading your browser. We are sorry for the inconvenience, an Ajax-free version is on its way");
		return;
	}
	xmlObj.onreadystatechange = function() {
		if ( (xmlObj.readyState==4) && (xmlObj.status!=200) ) alert("There was a problem with telling the server you downloaded something." + '\n' + "If your download failed, please contact me. (Use the contact page)");
	}
	xmlObj.open("POST", "download.php", true);
	toSend = "f=" + file + "&r=" + Math.random();
	xmlObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	xmlObj.send(toSend);
}
function moveStart(e) {
	Fx = e.clientX;
	Fy = e.clientY;
	move=1;
}
function moveMenu(e) {
	if (!move) return;
	var menuObj = document.getElementById('menu');
	x = e.clientX - Fx;
	y = e.clientY - Fy;
	Fx = e.clientX;
	Fy = e.clientY;
	menuObj.style.left = menuObj.offsetLeft + x;
	menuObj.style.top = menuObj.offsetTop + y;
}
function minimize() {
	var obj = document.getElementById('mainmenu');
	mC = obj.offsetHeight;
	min();
}
function min() {
	var obj = document.getElementById('mainmenu');
	var bigObj = document.getElementById('menu');
	if (obj.offsetHeight>15) obj.style.height = obj.offsetHeight - 1;
	if (bigObj.offsetWidth>75) bigObj.style.width = bigObj.offsetWidth - 1;
	if ( (obj.offsetHeight>15) || (bigObj.offsetWidth>75) ) setTimeout("min()", 10);
	else {
		var obj = document.getElementById('minmax');
		obj.innerHTML = "<a href=\"javascript:void(0)\" onClick=\"maximize(true)\" class=\"maxmin\">+</a>";
		document.getElementById('menutop').style.background = "url('roundrect/?s=75x30&c=8080FF') no-repeat top center";
		document.getElementById('menubot').style.background = "url('roundrect/?s=75x30&c=8080FF') no-repeat bottom center";
	}
}
function maximize(chg) {
	if (chg) {
		document.getElementById('menutop').style.background = "url('roundrect/?s=150x30&c=8080FF') no-repeat top center";
		document.getElementById('menubot').style.background = "url('roundrect/?s=150x30&c=8080FF') no-repeat bottom center";
	}
	var obj = document.getElementById('mainmenu');
	var bigObj = document.getElementById('menu');
	if (obj.offsetHeight<=mC) obj.style.height = obj.offsetHeight + 1;
	if (bigObj.offsetWidth<150) bigObj.style.width = bigObj.offsetWidth + 1;
	if ( (obj.offsetHeight<=mC) || (bigObj.offsetWidth<150) ) setTimeout("maximize()", 10);
	else {
		var obj = document.getElementById('minmax');
		obj.innerHTML = "<a href=\"javascript:void(0)\" onClick=\"minimize()\" class=\"maxmin\">¯</a>";
	}
}