Navigation.prototype.HEIGHT_CLOSED = 25;
Navigation.prototype.BOTTOM_MARGIN = 20;
Navigation.prototype.WIN_IE50 = (navigator.userAgent.toLowerCase().indexOf("msie 5.0") > 0); 
Navigation.prototype.WIN_IE5PLUS = ((navigator.userAgent.toLowerCase().indexOf("msie") > 0) && (navigator.userAgent.toLowerCase().indexOf("msie 5.0") < 0)); 
Navigation.prototype.WIN_IE60 = (navigator.userAgent.toLowerCase().indexOf("msie 6.0") > 0);

function Navigation (container, bottomImage, HTML, extFrame) {
	this.navigation = document.getElementById(container);
	this.navigation.innerHTML = HTML;
	this.closing = -1;
	this.opening = -1;
	this.openImage = document.getElementById(bottomImage);
	this.logoImage = document.getElementById('navlogo');
	this.allItems = this.navigation.getElementsByTagName("li");
	this.initAllItems();
	this.subLists = this.navigation.getElementsByTagName('ul')[0].getElementsByTagName('ul');
	//this.targetHeight = this.getHeight() + this.HEIGHT_CLOSED + this.BOTTOM_MARGIN;
	this.targetHeight = 220 + this.HEIGHT_CLOSED + this.BOTTOM_MARGIN;
	this.isOpen = false;
	if (!document.all || this.WIN_IE50) this.initExtFrame();	
	/* iframe behind navigation for IE 5.5+ to hide selectboxes */
	if (document.all && !this.WIN_IE50) {
		this.selectHider = this.createHider();
	}
	if (this.WIN_IE50) {
		this.selectBoxes = document.getElementsByTagName('select');
	}
	this.navigation.onmouseover = createContextFunction(this, "open");
	this.navigation.onmouseout = createContextFunction(this, "close");
	/* IE initialization for navigation entries */
	if (document.all) {
		this.initIE();
	}
	this.placeItems();
	/*if (document.getElementById('sitemap')) {
		generateSitemap();
		if (this.WIN_IE50) window.resizeBy(0, 1);
	}*/
	this.setFullHeight();
	if (getCookie('jffp')) {if (getCookie('jffp').length > 10) this.clearLoginEntries()};
}
Navigation.prototype.initIE = function () {
	for (var i=0; i < this.allItems.length; i++) {
		var node = this.allItems[i];
		node.onmouseover = function () {
			this.className += "over";
		}
		node.onmouseout = function () {
			this.className = this.className.replace("over", "");
		}
	}
}
Navigation.prototype.initExtFrame = function () {
	this.extFrame = document.getElementById('extFrame');
	if (this.extFrame) {
		this.extFrame.style.position = 'relative'; /* ppkpatch: give iframe position: relative so top can be used instead of marginTop */
		this.extFrame.startPos = calculateTop(this.extFrame);
	}
}
Navigation.prototype.initAllItems = function () {
	for (var i = 0; i < this.allItems.length; i++) {
		if (this.allItems[i].className.indexOf('submenu') != -1) {
			// get rid of extra classes for sitemap layout
			if (this.allItems[i].className.indexOf('rightmap') != -1) {
				this.allItems[i].className = 'submenu';
			}
			this.allItems[i].submenu = this.allItems[i].getElementsByTagName('ul')[0];
			this.allItems[i].subItem = this.allItems[i].submenu.getElementsByTagName('li')[0];
		} else {
			this.allItems[i].submenu = null;
			this.allItems[i].subItem = null;
		}
	}
}
Navigation.prototype.open = function (e) {
	if (e) var dest = e.relatedTarget; else var dest = window.event.toElement;
	if (dest) if (dest.parentNode.id == 'home' || dest.parentNode.id == 'top' || dest.parentNode.id == 'ls_top' || dest.parentNode.id == 'maincontainer') return;
	//this.allItems[0].getElementsByTagName('a')[0].focus();
	//this.allItems[0].getElementsByTagName('a')[0].blur();
	if (this.WIN_IE50) {
		this.slideOpen()
	} else {
		if (this.closing > 0) {
			clearTimeout(this.closing);
			this.closing = -1;
		}
		if (this.opening < 0 && !this.isOpen) {
			this.opening = setTimeout(createContextFunction(this, "slideOpen"), 300);
		}
	}
}
Navigation.prototype.slideOpen = function () {
	this.openImage.style.display = 'block';
	this.logoImage.style.display = 'block';
	this.navigation.style.height = this.targetHeight + "px";
	if (this.selectHider) this.selectHider.style.display = 'block';
	if (this.selectBoxes) updateSelectBoxes(this.selectBoxes, 'hidden');
	if (this.extFrame && !this.isOpen) {
		this.extFrame.overLap = (this.HEIGHT_CLOSED + this.targetHeight - this.extFrame.startPos);
		this.extFrame.style.top = this.extFrame.overLap + "px"; /* ppkpatch: marginTop -> top */
	}
	if (!this.WIN_IE50) clearTimeout(this.opening);
	this.opening = -1;
	this.isOpen = true;
}
Navigation.prototype.close = function (e) {
	if (e) var dest = e.relatedTarget; else var dest = window.event.toElement;
	if (!isChild(this.navigation, dest)) {
		if (this.WIN_IE50) {
			this.slideClose();
		} else {		
			if (this.opening > 0) {
				clearTimeout(this.opening);
				this.opening = -1;
			}
			if (this.closing < 0 && this.isOpen) {
				this.closing = setTimeout(createContextFunction(this, "slideClose"), 300);
			}
		}
	}
	if (e) e.cancelBubble = true; else window.event.cancelBubble = true;
}
Navigation.prototype.slideClose = function () {
	this.openImage.style.display = 'none';
	this.logoImage.style.display = 'none';
	this.navigation.style.height = this.HEIGHT_CLOSED + "px";
	if (this.selectHider) this.selectHider.style.display = 'none';
	if (this.selectBoxes) updateSelectBoxes(this.selectBoxes, 'visible');
	if (this.extFrame) {
		this.extFrame.style.top = "0"; /* ppkpatch: marginTop -> top */
	}
	if (!this.WIN_IE50) clearTimeout(this.closing);
	this.closing = -1;
	this.isOpen = false;
}
Navigation.prototype.getHeight = function () {
	var targetHeight = 0;
	var height3rdLevel = 0;
	this.show();
	for (var i = 0; i < this.subLists.length; i++) {
		if (this.subLists[i].offsetHeight > targetHeight) targetHeight = this.subLists[i].offsetHeight;
		height3rdLevel = get3rdLevelHeight(this.subLists[i]);
		if (height3rdLevel > targetHeight) targetHeight = height3rdLevel;
	}
	this.hide();
	return targetHeight;
}
Navigation.prototype.show = function () {
	for (var i = 0; i < this.allItems.length; i++) {
		this.allItems[i].persistentClassName = this.allItems[i].className;
		this.allItems[i].className +="over";
		this.allItems[i].className +=" show";
	}
}
Navigation.prototype.hide = function () {
	for (var i = 0; i < this.allItems.length; i++) {
		this.allItems[i].className = this.allItems[i].persistentClassName;
	}
}
Navigation.prototype.setFullHeight = function () {
	for (var i = 0; i < this.subLists.length; i++) {
		this.subLists[i].style.height = "700px";
	}
}
Navigation.prototype.createHider = function () {
	var iframe = document.createElement('iframe');
	iframe.style.height = this.targetHeight + "px";
	iframe.style.width = this.navigation.offsetWidth + "px";
	iframe.frameBorder = '0';
	this.navigation.appendChild(iframe);
	return (iframe);
}
Navigation.prototype.clearLoginEntries = function () {
	var a;
	for (var i = 0; i < this.allItems.length; i++) {
		a = this.allItems[i].getElementsByTagName('a')[0];
		if (a.className.indexOf('login') != -1) a.className = '';
	}
}

Navigation.prototype.placeItems = function () {
	var mainItems = new Array();
	
	for (var i = 0; i < this.allItems.length; i++) {
		if (this.allItems[i].parentNode.className == 'level1') mainItems[mainItems.length] = this.allItems[i];
	}
	if (document.body.offsetWidth < 988) {
		mainItems[mainItems.length - 1].className += 'left';
		mainItems[mainItems.length - 1].id = 'lastleft';
		mainItems[mainItems.length - 2].className += 'left';
	}
	// force width of right-side nav items to display properly in ie
	if ((this.WIN_IE50) || (this.WIN_IE5PLUS)) {
		for (var i = 0; i < this.allItems.length; i++) {
			if (this.allItems[i].className == 'submenuleft') { 
				this.menu_item = this.allItems[i];
				this.checkWidth(this.menu_item);
			}
		}
	}
}
Navigation.prototype.checkWidth = function(menu_item) {
	this.menu_item = menu_item;
	this.wid = this.menu_item.offsetWidth;
	this.oddOrEven(this.wid);
	if (!this.WIN_IE60) {
		this.newWid += 15; //add right padding back on for ie6.0
	}
	this.menu_item.style.width = this.newWid;
}
Navigation.prototype.oddOrEven = function(wid) {
	this.wid = wid - 15; //remove right padding
	this.oe = this.wid % 2;
	if ((this.oe == 1) && (this.menu_item.id != "lastleft")) { this.wid++; }
	else if ((this.oe != 1) && (this.menu_item.id == "lastleft")) { this.wid++; }
	this.newWid = this.wid;
}
function get3rdLevelHeight(ul) {
	var height = 0;
	var maxHeight = 0;
	var currentYPos = 0;
	var secondLevelCounter = 0;
	var entries = ul.getElementsByTagName('li');
	
	for (var i = 0; i < entries.length; i++) {
		if (entries[i].parentNode.className == 'level2') {
			if (entries[i].className == 'submenuover') {
				currentYPos = entries[i].offsetTop;
				height = currentYPos + entries[i].getElementsByTagName('ul')[0].offsetHeight;
			}
			if (height > maxHeight) maxHeight = height;
		}
	}
	return maxHeight;
}
function updateSelectBoxes(boxes, visibility) {
	for (var i = 0; i < boxes.length; i++) {
		boxes[i].style.visibility = visibility;
	}
}

