// initializing navi object
var navi = {
	top: {
		activePoint:	null,
		activeLinkImage:		null,
		disable:		function() {
			if(this.activePoint) {
				this.activePoint = null;
				// assign the temp saved onmouseout event again
				if(this.tempOnMouseOut) {
				   this.activeLinkImage.onmouseout = this.tempOnMouseOut;
				   this.activeLinkImage.onmouseout();
				  }				
			}
		},
		enable:			function(newPoint) {
			this.activePoint = newPoint;
			
			// search for navi-image and save/overwrite the onmouseout-event
			this.activeLinkImage = newPoint.getElementsByTagName('img')[0];
			if(this.activeLinkImage) {
				this.tempOnMouseOut = this.activeLinkImage.onmouseout;
				this.activeLinkImage.onmouseout = null;
			}			
			naviSettings.timeout.clear();
		}
	},
	
	main:{
		activeArea:		null,
		activePoint:	null,
		hide:		function() {
			if(this.activeArea) {
				this.activeArea.style.visibility 		= 'hidden';
			}
		},
		enable:			function(parentPoint) {
			naviSettings.timeout.clear();
			
		},
		show:			function(parentPoint) {
			var pos = findPos(parentPoint);
			myId = parentPoint.getAttribute('myId');
			this.activeArea = document.getElementById('mainNaviArea_' + myId);
			if(this.activeArea) {
				this.activeArea.style.left = pos[0] - naviSettings.main.offsetLeft + "px";
				this.activeArea.style.top = pos[1] + parentPoint.offsetHeight + "px";
				this.activeArea.style.visibility = "visible";
			}	
		}
	}
}


// timeout adaptor
function startNaviTimeout() {
	naviSettings.timeout.start();
}


// function returns the position of the selected element
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
	}
	return [curleft,curtop];
}



// hiding all active navi elements
function deactivatingNavi() {
	navi.top.disable();
	navi.main.hide();
}

// shows the main navigation
function showMainNavi(topNaviPoint) {
	deactivatingNavi();
	navi.top.enable(topNaviPoint);
	navi.main.show(topNaviPoint);
}

function enableMainNavi(topNaviPoint) {
	navi.main.enable(topNaviPoint);
}


// Switch off Opacity for Mac, because of the Flash in Background
function switchOffOpacity() {
	var allDivs = document.getElementsByTagName('div');
	for (var i=0; i<allDivs.length; i++) {
		allDivs[i].style.MozOpacity = 1;
	}
}