// Image Function
function nextImg() {
	if (currentPic < numPics) {
		currentPic += 1;
	} else {
		currentPic = 1;
	}
	switchtoPic(currentPic);
}
function prevImg() {
	if (currentPic > 1) {
		currentPic -= 1;
	} else {
		currentPic = numPics;
	}
	switchtoPic(currentPic);
}
function switchtoPic(num) {
	document.getElementById("picCounter").innerHTML = num + " | " + numPics;
	imgObj = document.getElementById("background_img");
	imgObj.style.visibility = "hidden";
	imgObj.src = "images/pics/"+pics[num][0]+".jpg";
	imgObj.onload = setImage;
	
	if (pics[num][1] || pics[num][2]) {
		document.getElementById("info").style.visibility = "visible";
		document.getElementById("infotext").innerHTML = "<h2>"+pics[num][1]+"</h2>";
		document.getElementById("infotext").innerHTML += pics[num][2];
	} else {
		document.getElementById("info").style.visibility = "hidden";
	}
}


// Tooltip
var toolTipMover = null;
function showTooltip() {
	document.getElementById("infotext").style.visibility = "visible";
	window.clearInterval(toolTipMover);
	toolTipMover = window.setInterval("openTooltip()", 50);
}
function openTooltip() {
	obj = document.getElementById("info");
	var height = obj.offsetHeight;
	var width = obj.offsetWidth;
	obj.style.height = height + (330 - height) / 5 + "px";
	obj.style.width = width + (555 - width) / 5 + "px";
	if (height >= 328 && width >= 553) {
		window.clearInterval(toolTipMover);
		obj.style.height = "330px";
		obj.style.width = "555px";
	}
}
function hideTooltip() {
	document.getElementById("infotext").style.visibility = "hidden";
	window.clearInterval(toolTipMover);
	toolTipMover = window.setInterval("closeTooltip()", 50);
}
function closeTooltip() {
	obj = document.getElementById("info");
	var height = obj.offsetHeight;
	var width = obj.offsetWidth;
	obj.style.height = height + (35 - height) / 5 + "px";
	obj.style.width = width + (35 - width) / 5 + "px";
	if (height <= 37 && width <= 37) {
		window.clearInterval(toolTipMover);
		obj.style.height = "35px";
		obj.style.width = "35px";
	}
}


// Admin - Löschen bestätigen
function sureDelete(obj, msg) {
	var check = confirm(msg);
	if (check) {
		obj.checked = "checked";
	} else{
		obj.checked = "";
	}
}

// Hintergrundbild positionieren
function setImage() {
	imgObj = document.getElementById("background_img");
	containerObj = document.getElementById("main");
	imgObj.style.height = containerObj.offsetHeight + "px";
	imgObj.style.position = "absolute";
	imgObj.style.left = (containerObj.offsetWidth - imgObj.offsetWidth) / 2 + "px";
	imgObj.style.visibility = "visible";
}


// Kindelement von ...
function isPartOf(obj, parent) {
	var isPart = false;
	while (obj.nodeName != 'HTML') {
		if (obj.id == parent) {
			isPart = true;
			break;
		}
		obj= obj.parentNode
	}
	
	return isPart;
}

// Menügrafiken wechseln
function toggleMenu(obj) {
	closeSubMenu();
	// SUbmenu
	/*
	switch (obj.parentNode.id) {
		case "sub1":
			document.getElementById("sub_menu").innerHTML = designMenu;
			break;
		case "sub2":
			document.getElementById("sub_menu").innerHTML = photoMenu;
			break;
		default:
			document.getElementById("sub_menu").innerHTML = "";
			break;
	}*/

	// Anmachen
	if (obj.src.match(/_off/)) {
		obj.src = obj.src.replace(/_off/, "_on");
	}
	// Ausmachen
	else {
		obj.src = obj.src.replace(/_on/, "_off");
	}
}

function setDesign() {
	document.getElementById("sub_menu").innerHTML = designMenu;
}
function setPhoto() {
	document.getElementById("sub_menu").innerHTML = photoMenu;
}

// Menü schliessen
var menuObj = null;
var menuMover = null;
var menuCloser = null;
function startCloseMenu(e) {
	// testen ob Element von Menü
	if (!e) var e = window.event;
	var relTarg = e.relatedTarget || e.toElement;
	if (!isPartOf(relTarg, "menu")) {
		menuCloser = window.setTimeout("closeMenu()", 200);
	}
}
function stopCloseMenu() {
	window.clearTimeout(menuCloser);
}
function closeMenu() {
	closeSubMenu();
	menuObj = document.getElementById("menu");
	menuObj.onmouseout = null;
	document.getElementById("menubar").onmouseover = openMenu;
	window.clearInterval(menuMover);
	arrowObj = document.getElementById("menu_arrow");
	arrowObj.src = "images/menu_arrow_right.png";
	menuMover = window.setInterval("moveMenuLeft()", 50);
}
function moveMenuLeft() {
	var pos = getObjPosition(menuObj);
	menuObj.style.left = pos.x + (-420 - pos.x) / 5 + "px";
	if (pos.x <= -415) {
		window.clearInterval(menuMover);
	}
}

// Menü öffnen
function openMenu() {
	window.clearInterval(menuMover);
	menuObj = document.getElementById("menu");
	document.getElementById("menubar").onmouseover = null;
	menuObj.onmouseout = startCloseMenu;
	stopCloseMenu();
	arrowObj = document.getElementById("menu_arrow");
	arrowObj.src = "images/menu_arrow_left.png";
	menuMover = window.setInterval("moveMenuRight()", 50);
}
function moveMenuRight() {
	var pos = getObjPosition(menuObj);
	menuObj.style.left = pos.x + (0 - pos.x) / 5 + "px";
	if (pos.x >= -5) {
		window.clearInterval(menuMover);
		document.getElementById("sub_menu").innerHTML = designMenu;
		document.getElementById("sub1").onmouseup = openSubMenu;
		document.getElementById("sub2").onmouseup = openSubMenu;
	}
}

// Submenu öffnen
var subMenuObj = null;
var subMenuMover = null;
var subMenuCloser = null;
function openSubMenu() {
	window.clearInterval(subMenuMover);
	document.getElementById("sub1").onmouseup = null;
	document.getElementById("sub2").onmouseup = null;
	document.getElementById("sub_menu").onmouseover = null;
	document.getElementById("sub1").onmouseout = startCloseSubMenu;
	document.getElementById("sub2").onmouseout = startCloseSubMenu;
	document.getElementById("sub_menu").onmouseout = startCloseSubMenu;
	stopCloseSubMenu();
	stopCloseMenu();
	subMenuObj = document.getElementById("sub_menu_container");
	subMenuMover = window.setInterval("moveSubMenuUp()", 50);
}
function moveSubMenuUp() {
	var height = subMenuObj.offsetHeight;
	subMenuObj.style.height = height + (216 - height) / 5 + "px";
	if (height >= 215) {
		subMenuObj.style.height = "216px";
		window.clearInterval(subMenuMover);
	}
}

// Submenü Schliessen
function startCloseSubMenu(e) {
	if (!e) var e = window.event;
	var relTarg = e.relatedTarget || e.toElement;
	if (!isPartOf(relTarg, "sub1") && !isPartOf(relTarg, "sub2") && !isPartOf(relTarg, "sub_menu") && !isPartOf(relTarg, "sub_menu_container2")) {
		subMenuCloser = window.setTimeout("closeSubMenu()", 200);
	}
}
function stopCloseSubMenu() {
	window.clearTimeout(subMenuCloser);
}
function closeSubMenu() {
	window.clearInterval(subMenuMover);
	document.getElementById("sub1").onmouseout = null;
	document.getElementById("sub2").onmouseout = null;
	document.getElementById("sub_menu").onmouseout = null;
	document.getElementById("sub1").onmouseup = openSubMenu;
	document.getElementById("sub2").onmouseup = openSubMenu;
	document.getElementById("sub_menu").onmouseover = openSubMenu;
	subMenuObj = document.getElementById("sub_menu_container");
	subMenuMover = window.setInterval("moveSubMenuDown()", 50);
}
function moveSubMenuDown() {
	var height = subMenuObj.offsetHeight;
	subMenuObj.style.height = height + (0 - height) / 5 + "px";
	if (height <= 2) {
		subMenuObj.style.height = "0px";
		window.clearInterval(subMenuMover);
	}
}

// StatusLeiste schliessen
var thumbObj = null;
var thumbMover = null;
var thumbCloser = null;
function startCloseThumb(e) {
	// testen ob Element von Menü
	if (!e) var e = window.event;
	var relTarg = e.relatedTarget || e.toElement;
	if (!isPartOf(relTarg, "thumb_bar")) {
		thumbCloser = window.setTimeout("closeThumb()", 200);
	}
}
function stopCloseThumb() {
	window.clearTimeout(thumbCloser);
}
function closeThumb() {
	thumbObj = document.getElementById("thumb_bar");
	thumbObj.onmouseout = null;
	document.getElementById("thumbButton").onmouseover = openThumb;
	window.clearInterval(thumbMover);
	thumbMover = window.setInterval("moveThumbDown()", 50);
}
function moveThumbDown() {
	var height = thumbObj.offsetHeight;
	thumbObj.style.height = height + (0 - height) / 5 + "px";
	if (height <= 2) {
		thumbObj.style.height = "0px";
		window.clearInterval(thumbMover);
	}
}
function openThumb() {
	window.clearInterval(thumbMover);
	thumbObj = document.getElementById("thumb_bar");
	document.getElementById("thumbButton").onmouseover = null;
	document.getElementById("thumbButton").onmouseout = startCloseThumb;
	thumbObj.onmouseover = openThumb;
	thumbObj.onmouseout = startCloseThumb;
	stopCloseThumb();
	thumbMover = window.setInterval("moveThumbUp()", 50);
}
function moveThumbUp() {
	var height = thumbObj.offsetHeight;
	thumbObj.style.height = height + (52 - height) / 5 + "px";
	if (thumbObj.style.height >= 50) {
		thumbObj.style.height = "52px";
		window.clearInterval(thumbMover);
	}
}


// Position von Element ermitteln
function getObjPosition(element) {
	var elem = element, tagname = "", x = 0, y = 0;

	while ((typeof(elem) == "object") && (typeof(elem.tagName) != "undefined")) {
		y += elem.offsetTop;
		x += elem.offsetLeft;
		tagname = elem.tagName.toUpperCase();

		if (tagname == "BODY" || tagname == "HTML") {
			elem = 0;
		}

		if (typeof(elem) == "object") {
			if (typeof(elem.offsetParent) == "object") {
				elem = elem.offsetParent;
			}
		}
	}

	position = new Object();
	position.x = x;
	position.y = y;
	return position;
}
