Navigation = function () {
	//log("constructor");

	this.opener = new Animator(40, 200, this.setHeight, this.createContextFunction("show"));
	this.opener.setType(Animator.prototype.EASEOUT);
	this.opener.setStep(4);
	this.closer = new Animator(200, 40, this.setHeight, this.createContextFunction("hide"));
	this.closer.setType(Animator.prototype.NONE);
	this.closer.setStep(5);

	this.OPEN    = 0;
	this.OPENING = 1;
	this.CLOSED  = 2;
	this.CLOSING = 3;
	this.state = this.CLOSED;

	document.getElementById("navigation").onmouseover = this.createContextFunction("enter");
	document.getElementById("main").onmouseover = document.getElementById("eventarea").onmouseover = this.createContextFunction("leave");

	/* open/close submenu's, attach menu array to upper ul */
	var uls = document.getElementById("navigation").getElementsByTagName("ul");
	var navmenus = new Array();
	document.getElementById("navigation").menus = navmenus;

	this.currentActive = null;

	var ullen = uls.length;
	for (var i=0; i < ullen; i++) {
		var parent = uls[i].parentNode;
		var isNavChild = (parent.parentNode.id == "navigation");
		if (isNavChild) {
			parent.submenu = uls[i];
			navmenus.push(parent);
			uls[i].className = "closed";
	
			var aref = parent.getElementsByTagName("a")[0];

			// find current active main item
			if ((this.currentActive == null) && (aref.className == "active")) {
				this.currentActive = aref;
			}
			var curActive = this.currentActive;

			aref.onmouseover = function () {
				for (var i=0; i < navmenus.length; i++) {
					navmenus[i].submenu.className = "closed";
					var main_a = navmenus[i].getElementsByTagName("a")[0];
					if ((curActive == null) || (main_a != curActive)) {
						main_a.className = "";
					}
				}
				this.parentNode.submenu.className = "open";
				this.className = "active";
			}
		}

		if (!isNavChild) parent.parentNode.style.display = "block";
		uls[i].style.display = "block";
		var width = (!isNavChild) ? uls[i].offsetWidth-10 : uls[i].offsetWidth;
		uls[i].style.display = "";
		if (!isNavChild) parent.parentNode.style.display = "";
		var as = uls[i].getElementsByTagName("a");
		for (var a=0; a < as.length; a++) as[a].style.width = width+"px";
	}
}
Navigation.prototype.enter = function () {
	//log("enter");
	if (this.state == this.CLOSED) {
		document.getElementById("dropdown").style.display = "block";
		document.getElementById("eventarea").style.display = "block";
		this.opener.start();
		this.state = this.OPENING;
	}
}
Navigation.prototype.show = function() {
	this.state = this.OPEN;
}

Navigation.prototype.leave = function () {
	//log("leave");
	if (this.state == this.OPENING || this.state == this.OPEN) {
		if (this.state == this.OPENING) this.opener.stop();//cancel opening menu
		this.closer.start();
		this.state = this.CLOSING;
	}
}
Navigation.prototype.hide = function () {
	document.getElementById("eventarea").style.display = "none";
	document.getElementById("dropdown").style.display = "none";
	var menus = document.getElementById("navigation").menus;
	var len = menus.length;
	for (var i=0; i < len; i++) {
		var item = menus[i];
		item.submenu.className = "closed";
		item.getElementsByTagName("a")[0].className = "";
	}
	if (this.currentActive != null) {
		this.currentActive.className = "active";
	}
	this.state = this.CLOSED;
}

Navigation.prototype.setHeight = function (value) {
	if (value > 155) {
		document.getElementById("navigation").className = "active";
	} else {
		document.getElementById("navigation").className = "passive";
	}
	document.getElementById("subnavigation").style.height = value + "px";
}
Navigation.prototype.createContextFunction = function (method) {
	var context = this;
	return (function(){
		eval("context."+method+"()");
		return false;
    });
}
ToolTip = function () {
	var tip = document.createElement("div");
	tip.id = "largetooltip";
	document.getElementById("center").appendChild(tip);
	var divs = document.getElementsByTagName("div");
	for (var i=0; i < divs.length; i++) {
		if (divs[i].className.indexOf("tooltip") != -1) {
			divs[i].parentNode.tooltip = divs[i];
			divs[i].parentNode.onmouseover = function () {
				document.getElementById("largetooltip").innerHTML = this.tooltip.innerHTML;
				document.getElementById("largetooltip").style.display = "block";
			}
			divs[i].parentNode.onmouseout = function () {
				document.getElementById("largetooltip").style.display = "none";
				document.getElementById("largetooltip").innerHTML = "";
			}
		}
	}
}