




var nav = null;
if ((navigator.userAgent.indexOf("Gecko") != -1) || (navigator.appName.indexOf("Netscape") != -1)) {
	nav = "NN";
} else {
	nav = "IE";
}

function getOffset(element, offsetName) {
	var result = 0;
	while (element != null) {
		result += eval("element." + offsetName);
		element = element.offsetParent;
	}
	return result;
}

function openWindow(url) {
	wndName = "popupWindow";
    if ((url == null) || (url == '#')) {
		return;
	}
	var w = 350;
	var h = 170;
	var l = (screen.width) ? ((screen.width - w) / 2) : 150;
	var t = (screen.height) ? ((screen.height - h) / 2) : 150;
	var wndFeatures = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,top=" + t + ",left=" + l + ",width=" + w + ",height=" + h;
	var popupWnd = window.open(url, wndName, wndFeatures);
	if(popupWnd != null) {
		popupWnd.moveTo(l,t);
		if (popupWnd.opener == null) {
			popupWnd.opener = self;
		}
		popupWnd.focus();
	}
}

function menuItemHightlightOn () {this.container.className = this.onstyle;}
function menuItemHightlightOff () {this.container.className = this.offstyle;}
var minSubmenuWidth = 159;
function MenuItem (item, container) {
	this.hasSubMenu = false;
	this.container = container;
	this.timeout = false;
	this.submenu = false;
	this.offstyle = "menuitem off";
	this.onstyle = "menuitem on";
	this.highlightOn = menuItemHightlightOn;
	this.highlightOff = menuItemHightlightOff;
	if (item) {
		if (item.offsetWidth < minSubmenuWidth) {
			item.style.width = minSubmenuWidth + "px";
			item.getElementsByTagName("table").item(0).style.width = "100%";
			item.getElementsByTagName("table").item(1).style.width = "100%";
		}
		item.style.left = getOffset(container, "offsetLeft") - item.offsetWidth;
		item.style.top = getOffset(container, "offsetTop");
		this.submenu = item;
		this.onstyle = "menuitem on sub";
		this.hasSubMenu = true;
	}
}

var currentSubmenuId = 0;
var menuItems = new Array(null);
function initMenuItems (itemsLength) {
	for (i = 1; i <= itemsLength; i++) {
		menuItems[i] = new MenuItem(document.getElementById("submenu_" + i), document.getElementById("menu_" + i));
	}
}

function TextPlane (txt, textContainer, downButton, upButton) { // scrolling item properties container object
	if (nav == "NN") {
		textContainer.style.width = textContainer.offsetWidth;
		textContainer.style.height = textContainer.offsetHeight;
		textContainer.style.left = getOffset(textContainer, "offsetLeft");
		textContainer.style.top = getOffset(textContainer, "offsetTop");
		textContainer.style.position = "absolute";
	}
	this.content = txt;
	this.textAreaHeight = textContainer.offsetHeight;
	this.textHeight = this.content.offsetHeight;
	this.canScroll = (this.textHeight > this.textAreaHeight) ? true : false;
	if (this.canScroll) {
		downButton.style.visibility = "visible";
		upButton.style.visibility = "visible";
	}
}



var blankImg = new Image();
blankImg.src = "/resources/graphics/transparent.gif";

function filterAttributes (sAttributeName, sAttributeValue) {
	if (sAttributeName == "align") {
		if ((sAttributeValue == "center") || (sAttributeValue == "middle")) {
			return "center";
		} else {
			return sAttributeValue;
		}
	}
	return sAttributeValue;
}

var maxRoundedImgWidth = 100;
var maxRoundedImgHeight = 100;
function roundImageCorners (sContainerName) {
	var affectedImgFirst = document.getElementById(sContainerName).getElementsByTagName("img");
	var affectedImg = new Array();
	var blankImgUrl = blankImg.src;
	for (i = 0; i < affectedImgFirst.length; i++) {
		var img = affectedImgFirst[i];
		if ((img.width >= maxRoundedImgWidth) && (img.height >= maxRoundedImgHeight) && (img.src != blankImgUrl)) affectedImg[affectedImg.length] = img;
	}
	for (i = 0; i < affectedImg.length; i++) {
		var img = affectedImg[i];
		var imgTable = document.createElement("table");
		if (img.align) imgTable.align = filterAttributes("align", img.align);
		if (img.parentNode) {
			if (img.parentNode.align) imgTable.align = filterAttributes("align", img.parentNode.align);
			if (img.parentNode.style) {
				if (img.parentNode.style.textAlign) imgTable.align = img.parentNode.style.textAlign;
			}
		}
		imgTable.border = 0;
		imgTable.style.width = img.width + "px";
		imgTable.style.height = img.height + "px";
		imgTable.cellSpacing = 0;
		imgTable.cellPadding = 0;
		var cell = imgTable.insertRow(0).insertCell(0);
		cell.appendChild(writeDiv(img.src, blankImgUrl, -6, 0, (img.width - 12), 1));
		cell.appendChild(writeDiv(img.src, blankImgUrl, -4, -1, (img.width - 8), 1));
		cell.appendChild(writeDiv(img.src, blankImgUrl, -3, -2, (img.width - 6), 1));
		cell.appendChild(writeDiv(img.src, blankImgUrl, -2, -3, (img.width - 4), 1));
		cell.appendChild(writeDiv(img.src, blankImgUrl, -1, -4, (img.width - 2), 2));
		cell.appendChild(writeDiv(img.src, blankImgUrl, 0, -6, img.width, (img.height - 12)));
		cell.appendChild(writeDiv(img.src, blankImgUrl, -1, -(img.height - 6), (img.width - 2), 2));
		cell.appendChild(writeDiv(img.src, blankImgUrl, -2, -(img.height - 4), (img.width - 4), 1));
		cell.appendChild(writeDiv(img.src, blankImgUrl, -3, -(img.height - 3), (img.width - 6), 1));
		cell.appendChild(writeDiv(img.src, blankImgUrl, -4, -(img.height - 2), (img.width - 8), 1));
		cell.appendChild(writeDiv(img.src, blankImgUrl, -6, -(img.height - 1), (img.width - 12), 1));
		cell.style.textAlign = "center";
		cell.style.verticalAlign = "top";
		img.parentNode.replaceChild(imgTable, img);
	}
}

function writeDiv (sBgImgUrl, sBlankImgUrl, iBgOffsetLeft, iBgOffsetTop, iDivWidth, iDivHeight) { // NEEDED FOR PREVIOUS FUNCTION
	var block = document.createElement("div");
	block.style.width = iDivWidth + "px";
	block.style.height = iDivHeight + "px";
	block.style.backgroundRepeat = "no-repeat";
	block.style.backgroundPosition = iBgOffsetLeft + "px " + iBgOffsetTop + "px";
	block.style.backgroundImage = "url('" + sBgImgUrl + "')";
	if (nav == "IE") {
		blankImg = document.createElement("img");
		blankImg.width = iDivWidth;
		blankImg.height = iDivHeight;
		blankImg.src = sBlankImgUrl;
		block.appendChild(blankImg);
	} else {
		block.style.left = (iBgOffsetLeft * -1) + "px";
		block.style.position = "relative";
	}
	return block;
}





var updown;
var textPlanes = new Array(2);
textPlanes["left"] = new Object();
textPlanes["right"] = new Object();

function initPage(bIsEmptyPage) {
	if (navigator.appVersion.indexOf("Safari") != -1) openWindow("/pn/opencms/sv/safari_info.html");
	if (!isNaN(rand)) document.getElementById("container").style.backgroundImage = "url('" + bgPics[rand] + "')";
	if (!bIsEmptyPage) {
		var obj;
		/* background init */
		if (navigator.appName.indexOf("Internet Explorer") != -1) {
			document.getElementById("texttable").style.position = "relative";
			document.getElementById("texttable").style.zIndex = 3;
			document.getElementById("texttablebg").style.visibility = "visible";
			document.getElementById("texttablebg").style.setExpression("left", "document.getElementById('mastertable').offsetLeft + 34 - 22");
		} else {
			document.getElementById("textcont").style.backgroundImage = "url('" + NSbgImageUrl + "')";
			document.getElementById("textcont").style.backgroundPosition = "0 13px";
		}
		/* scrolling init */
		if (document.getElementById("textLeft")) {
			textPlanes["left"] = new TextPlane(document.getElementById("textLeft"), document.getElementById("textContainerLeft"), document.getElementById("leftDownScroller"), document.getElementById("leftUpScroller"));
			roundImageCorners("textLeft");
		}
		if (document.getElementById("textRight")) {
			textPlanes["right"] = new TextPlane(document.getElementById("textRight"), document.getElementById("textContainerRight"), document.getElementById("rightDownScroller"), document.getElementById("rightUpScroller"));
			roundImageCorners("textRight");
		}
		if (document.getElementById("textSingle")) {
			roundImageCorners("textSingle");
		}
	}
	initMenuItems(document.menuItemsLength);
}

function moveUp(speed, textLayer) {
	updown = window.setInterval("doMove(" + speed + ", \"" + textLayer + "\")", 10);
}

function moveDown(speed, textLayer) {
	updown = window.setInterval("doMove(-" + speed + ", \"" + textLayer + "\")", 10);
}

maxTextPosition = 0;

function doMove(factor, textLayer) { // -1 = down; 1 = up;
	var obj = textPlanes[textLayer];
	obj.maxTextPosition = obj.textAreaHeight - obj.textHeight;
	if (((obj.content.offsetTop >= 0) && (factor > 0)) || ((obj.content.offsetTop <= obj.maxTextPosition) && (factor < 0))) {
		stopScrolling();
		return;
	}
	var newPosition = obj.content.offsetTop + factor;
	if (newPosition > 0) newPosition = 0;
	if (newPosition < obj.maxTextPosition) newPosition = obj.maxTextPosition;
	obj.content.style.top = newPosition;
}

function stopScrolling () {
	window.clearInterval(updown);
}

function show (menuId) {
	if (!menuItems[menuId]) return;
	menuItems[menuId].highlightOn();
	if (menuItems[menuId].hasSubMenu) {
		if ((currentSubmenuId != 0) && (currentSubmenuId != menuId)) doHide(currentSubmenuId);
		menuItems[menuId].submenu.style.visibility = "visible";
		currentSubmenuId = menuId;
	}
}

function hide (menuId) {
	if (!menuItems[menuId]) return;
	if (menuItems[menuId].hasSubMenu) {
		menuItems[menuId].timeout = window.setTimeout("doHide(" + menuId + ")", 100);
	} else {
		menuItems[menuId].highlightOff();
	}
}

function doNotHide (menuId) {
	if (menuItems[menuId]) window.clearTimeout(menuItems[menuId].timeout);
}

function doHide (menuId) {
	menuItems[menuId].highlightOff();
	if (menuItems[menuId].hasSubMenu) {
		menuItems[menuId].submenu.style.visibility = "hidden";
		currentSubmenuId = 0;
	}
}
