function getPinkieBoxRequestObject() {
	var req = null;
	try {
		req = new XMLHttpRequest();
	}
	catch (ms) {
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (nonms) {
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (failed) {
				req = null;
			}
		}
	}
	if (req == null)
		alert("Error creating request object!");
	return req;
}
function initPinkieBox(dest, objId, value) {
	var http = getPinkieBoxRequestObject();
	http.open("GET", window.location.href.substring(0, window.location.href.lastIndexOf("/")) + dest + "?IMAGE=" + encodeURIComponent(value), true);
 	http.onreadystatechange = function() {
 		if (http.readyState == 4)
 			if (http.responseText != "") {
				var response = http.responseText;
 				imageWidth = http.responseText.substr(0, response.indexOf("x"));
 				imageHeight = http.responseText.substr(response.indexOf("x")+1, (response.length - response.indexOf("x") - 1));
				imageHeight = parseInt(imageHeight) + parseInt(40);
				screenWidth = window.innerWidth || (window.document.documentElement.clientWidth || window.document.body.clientWidth);
				screenHeight = window.innerHeight || (window.document.documentElement.clientHeight || window.document.body.clientHeight);
				xPos = (screenWidth - imageWidth) * 0.5;
				yPos = (screenHeight - imageHeight) * 0.5;
				document.getElementById(objId).style.width=imageWidth+"px";
				document.getElementById(objId).style.height=imageHeight+"px";
				document.getElementById(objId).style.left=xPos+"px";
				document.getElementById(objId).style.top=yPos+"px";
				document.getElementById(objId+"_close").style.left=(imageWidth-19)+"px";
				document.getElementById(objId+"_close").style.top=(imageHeight-24)+"px";
			}
 	}
	http.send(null);
}

function openPinkieBox(objId, imgSrc) {
	document.getElementById(objId + "_img").src = imgSrc;
	initPinkieBox("/ajax/getPinkieBoxDimension.php", objId, imgSrc);
	document.getElementById('pinkiecurtain').style.visibility = 'visible';
	document.getElementById(objId).style.visibility = 'visible';
}
function closePinkieBox(objId) {
	document.getElementById('pinkiecurtain').style.visibility='hidden';
	document.getElementById(objId).style.visibility='hidden';
}
function MenuOver(obj, mainmenu) {
	obj.style.cursor = "pointer";
	if (mainmenu) {
		obj.style.backgroundImage = "url('images/menuselection.gif')";
		obj.style.backgroundRepeat = "repeat-x";
	}
	else {
		obj.style.backgroundImage = "url('images/menubg.jpg')";
		//obj.style.backgroundRepeat = "repeat-y";
	}
}
function MenuOut(obj) {
	obj.style.backgroundImage = "";
	obj.style.backgroundRepeat = "";
}
function getRequestObject() {
	var req = null;
	try {
		req = new XMLHttpRequest();
	}
	catch (ms) {
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (nonms) {
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (failed) {
				req = null;
			}
		}
	}
	if (req == null)
		alert("Error creating request object!");
	return req;
}
function ajaxSetContent(dest, key, value, subValue) {
	var http = getRequestObject();
	http.open("GET", window.location.href.substring(0, window.location.href.lastIndexOf("/")) + dest + "?" + key + "=" + value + (subValue == 0 ? "" : "&SUBKEY=" + subValue), true);
 	http.onreadystatechange = function() {
 		if (http.readyState == 4)
 			if (http.responseText != "") {
			 	document.getElementById("StoryContainer").innerHTML = http.responseText;
			}
 	}
	http.send(null);
}
function ajaxSetMenu(dest, key, value, subValue) {
	var http = getRequestObject();
	http.open("GET", window.location.href.substring(0, window.location.href.lastIndexOf("/")) + dest + "?" + key + "=" + value + (subValue == 0 ? "" : "&SUBKEY=" + subValue), true);
 	http.onreadystatechange = function() {
 		if (http.readyState == 4) {
		 	document.getElementById("SubMenu").innerHTML = http.responseText;
		}
 	}
	http.send(null);
}
function selectMainMenu(menuKey, obj) {
	divList = document.getElementsByTagName("div");
	for (var idx = 0; idx < divList.length; idx++) {
		if (divList[idx].className == "MainMenuEntry")
			divList[idx].style.fontWeight = "normal";
		if (divList[idx].className == "Header")
			divList[idx].style.backgroundImage = "url(styles/" + headerimages[menuKey - 1] + ")";
	}
	obj.style.fontWeight = "bold";
	ajaxSetContent("/contents.php", "KEY", menuKey, 0);
	ajaxSetMenu("/menu.php", "KEY", menuKey, 0);
}
function select(subMenuKey, menuKey, obj) {
	divList = document.getElementsByTagName("div");
	for (var idx = 0; idx < divList.length; idx++) {
		if (divList[idx].className == "MenuEntry")
			divList[idx].style.fontWeight = "normal";
	}
	obj.style.fontWeight = "bold";
	ajaxSetContent("/contents.php", "KEY", menuKey, subMenuKey);
	ajaxSetMenu("/menu.php", "KEY", menuKey, subMenuKey);
}
function openPictureView(title, address) {
	windowPictureView = window.open(address, "Bild", "width=800,height=650,scrollbars=yes,resizable=no");
	windowPictureView.focus();
}

