window.onresize = resizeNews;
window.onload = pageLoaded;

var cOpenContainerID = '';
var cMovedItemID = '';
var aItems = new Array(new Array ('news', '180px', '80px'), new Array ('information', '489px', '589px'), new Array ('exhibition', '280px', '280px'));

function pageLoaded () {
	var oDiv = document.getElementById('StartMuseum');
	for (var n=0; n<oDiv.childNodes.length; n++) {
		if (oDiv.childNodes[n].nodeType == '1') {
			oChild = oDiv.childNodes[n];
			for (var i=0; i<oChild.childNodes.length; i++) {
				if (oChild.childNodes[i].nodeName=='DIV') oChild.childNodes[i].style.display="none";
			}
		}
	}
	var aContainer = new Array(new Array ('newsContainer', '199px'), new Array ('informationContainer', '149px'), new Array ('exhibitionContainer', '149px'));
	for (var n=0; n<aContainer.length; n++) {
		oDiv = document.getElementById(aContainer[n][0]);
		oDiv.style.display="none";
		oDiv.style.top = aContainer[n][1];
	}
	
	for (var n=0; n<aItems.length; n++) {
		oDiv = document.getElementById(aItems[n][0]);
		oDiv.style.left = aItems[n][1];
	}
	
	oDiv = document.getElementById('exhibition');
	oDiv.style.top = '225px';
}

function showLocationInfo (oDiv) {
	if (cOpenContainerID) openContainer (cOpenContainerID);
	
	for (var n=0; n<oDiv.childNodes.length; n++ ) {
		if (oDiv.childNodes[n].nodeName=='DIV') {
			if (oDiv) if (oDiv.childNodes[n].style.display=="none")
				oDiv.childNodes[n].style.display="block";
			else
				oDiv.childNodes[n].style.display="none";
		}
	}
}

function openContainer (cContainerID) {
	var cItemID = cContainerID.substring(0, (cContainerID.length-9));
	
	if (cOpenContainerID) {
		if (cOpenContainerID == cContainerID) {
			closeContainer (cOpenContainerID, true);
			moveItem (cItemID, false);
			return;
		} else {
			closeContainer (cOpenContainerID, false);
			moveItem (cMovedItemID, false);
		}
	}
	var oDiv = document.getElementById(cContainerID);
	var nHmax = 0;
	var nExhibitionTop = 0;
	
	switch (cContainerID) {
		case 'newsContainer':
			nHmax = getMaxHeight ();
			break;
		case 'informationContainer':
			nHmax = 150;
			break;
		case 'exhibitionContainer':
			nHmax = 150;
			break;
			
		default:
			nHmax = 200;
	}
	oDiv.style.height = '25px';
	oDiv.style.display='block';
	
	animateContainer (cContainerID, nHmax, true);
	moveItem (cItemID, true);
}

function closeContainer (cContainerID, bMoveExhibition) {
	animateContainer (cContainerID, null, bMoveExhibition);
}

function animateContainer (cContainerID, nHmax, bMoveExhibition) {
	var oDiv = document.getElementById(cContainerID);
	oDiv.style.overflow = 'hidden';
	
	var cHeight = oDiv.style.height;
	var nH = parseInt (cHeight.substring(0, cHeight.length-2));
	var cTop = oDiv.style.top;
	var nContainerTop = parseInt (cTop.substring(0, cTop.length-2));
	
	if (nHmax) {
		if (nH < nHmax) {
			nH += 25;
			oDiv.style.height = nH + 'px';
			if (bMoveExhibition) setExhibitionTop (nH+nContainerTop);
			setTimeout ('animateContainer("'+cContainerID+'", '+nHmax+', '+ bMoveExhibition +')', 10);
		} else {
			if (bMoveExhibition) setExhibitionTop (nH+nContainerTop);
			oDiv.style.height = (nH-1) + 'px';
			oDiv.style.overflow = 'auto';
			cOpenContainerID = cContainerID;
		}
	} else {
		if (nH > 25) {
			nH -= 25;
			oDiv.style.height = nH + 'px';
			if (bMoveExhibition) setExhibitionTop (nH+nContainerTop);
			setTimeout ('animateContainer("'+cContainerID+'", '+nHmax+', '+ bMoveExhibition +')', 10);
		} else {
			oDiv.style.height = '25px';
			oDiv.style.display = 'none';
			if (bMoveExhibition) setExhibitionTop (nH+nContainerTop);
			if (cOpenContainerID == cContainerID) cOpenContainerID = '';
		}
	}
}


function setExhibitionTop (nTop) {
	var oDiv = document.getElementById('exhibition');
	nTop = Math.max (225, (nTop+1));
	oDiv.style.top = nTop + 'px';
}

function resizeNews () {
	var oDiv = document.getElementById('newsContainer');
	if (oDiv.style.display == 'block') {
		var nHmax = getMaxHeight ();
		
		var oExhibitionDiv = document.getElementById('exhibition');
		oDiv.style.height = nHmax + 'px';
		oExhibitionDiv.style.top = 200 + nHmax + 'px';
	}
}

function getMaxHeight () {
	var nHmax = 400;
	if (document.body.clientHeight) nHmax = Math.max(nHmax, document.body.clientHeight);
	if (window.innerHeight) nHmax = Math.max(nHmax, window.innerHeight);
	var nHmax = nHmax - 252; /*202 == unterkante #news-DIV; 50px == höhe #exhibition-DIV*/
	nHmax = Math.floor(nHmax/25)*25 - 25;
	
	return nHmax;
}

function moveItem (cItemID, bMark){
	var oDiv = document.getElementById(cItemID);
	/*var cLeft = oDiv.style.left;
	var nL = parseInt (cLeft.substring(0, cLeft.length-2));
	
	if (bDir != null) {
		var nDir = bDir ? 1 : -1;
		nL += (nPosDiff * nDir)
		oDiv.style.left = nL + 'px';
		cMovedItemID = cItemID;
	} else {
		
		for (var n=0; n<aItems.length; n++) {
			if (aItems[n][0] == cItemID) var nNewPos = aItems[n][1];
			nNewPos = parseInt (nNewPos.substring(0, nNewPos.length-2));
			oDiv.style.left = nNewPos + 'px';
		}
	}
	*/
	for (var n=0; n<aItems.length; n++) {
		if (aItems[n][0] == cItemID) var oItem = aItems[n];
	}
	var cNewPos = bMark ? oItem[2] : oItem[1];
	oDiv.style.left = cNewPos;
	if (bMark) cMovedItemID = cItemID;
}