var Navigation = {
	iRotationDelay		:	3000,
	
	aRotationTimeout	:	new Array(),
	iRotationTimeout	:	null,
	
	initialize	:	function()
	{
		Navigation.startRotation();
	
		Event.observe($('horizonmenu'), 'show:node', function(oEvt) {
			oEvt.stop();
			
			oEvt.memo.node.siblings().each(function(oItem) {
				oItem.removeClassName('aktiv');
				oItem.select('ul').invoke('hide');
			});
			
			with (oEvt.memo.node) {
				addClassName('aktiv');
			
				select('ul').first().show();

				if (Prototype.Browser.IE) {
					select('a').first().getAttribute('onmouseover')();
				}
				else {
					eval(select('a').first().getAttribute('onmouseover'));
				}
			}
		});
		
		Event.observe($('horizonmenu'), 'display:image', function(oEvt) {
			oEvt.stop();

			if (oEvt.memo.display === true) {
				$$('span.imagewrapper').invoke('show');
			}
			else {
				$$('span.imagewrapper').invoke('hide');
			}
		});
		
		Event.observe($('horizonmenu'), 'start:rotation', function(oEvt) {
			this.aRotationTimeout.push(window.setTimeout(function() {
				Navigation.startRotation();
			}, Navigation.iRotationDelay));
		}.bind(this));
		
		Event.observe($('horizonmenu'), 'stop:rotation', function(oEvt) {
			this.aRotationTimeout.each(function(iTimeout) {
				window.clearTimeout(iTimeout);
			});
			
			this.aRotationTimeout =new Array();
			
			window.clearTimeout(this.iRotationTimeout);
		}.bind(this));
		
		$$('ul#horizonmenu li').each(function(oItem) {
			Event.observe(oItem, 'mouseover', function(oEvt) {
				var oElement = Event.findElement(oEvt, 'li.navigation-node');
				
				with (Event.element(oEvt) ) {
					fire('show:node', {
						node	:	oElement
					});
					
					fire('stop:rotation');
				}
			});
			
			Event.observe(oItem, 'mouseout', function(oEvt) {
				Event.element(oEvt).fire('start:rotation');
			});
		});
		
		$$('ul#horizonmenu li.navigation-node').each(function(oItem) {
			Event.observe(oItem, 'mouseover', function(oEvt) {
				Event.findElement(oEvt, 'ul#horizonmenu').select('li.navigation-node li.node-level-2 ul').invoke('hide');
				
				Event.element(oEvt).fire('display:image', {
					display	:	true
				});
			});
		});

		$$('ul#horizonmenu li ul.navigation-level-2 li.node-level-2').each(function(oItem) {
			Event.observe(oItem, 'mouseover', function(oEvt) {
				oEvt.stop();

				var oElement = Event.findElement(oEvt, 'li.node-level-2');
				var oParent  = oElement.up('ul');
				
				if (oParent.aMouseOverTimeout) {
					oParent.aMouseOverTimeout.each(function(iTimeout) {
						window.clearInterval(iTimeout);
					});
				}
				
				oParent.aMouseOverTimeout = new Array();
				
				oParent.aMouseOverTimeout.push(window.setTimeout(function() {
					if (!oParent.aMouseStayedTimeout) {
						oParent.aMouseStayedTimeout = new Array();
					}
					
					oParent.aMouseStayedTimeout.push(window.setTimeout(function() {
						oElement.up('ul').select('li').each(function(oItem) {
							if (oItem.iTimeout != null) {
								window.clearTimeout(oItem.iTimeout);
								
								oItem.fire('display:image', {
									display	:	true
								});
		
								oItem.iTimeout = null;
							}
						});

						
						if (oElement.select('ul li').length > 0) {
							oElement.fire('show:children');
						}
						else
						{
							oElement.up('ul').select('ul').invoke('hide');
							
							oElement.fire('display:image', {
								display	:	true
							});
						}
					}, 200));
				}, 300));
			});

			Event.observe(oItem, 'mouseout', function(oEvt) {
				oEvt.stop();

				var oElement = Event.findElement(oEvt, 'li.node-level-2');
				var oParent  = oElement.up('ul');
				
				oParent.aMouseOverTimeout.push(window.setTimeout(function() {
					oElement.fire('hide:children');
				}, 2000));
			});

			Event.observe(oItem, 'hide:children', function(oEvt) {
				oEvt.stop();
				
				var oElement = Event.findElement(oEvt, 'li.node-level-2');
				var oParent	 = oElement.up('ul');
				
				if (!oElement.aTimeout) {
					oElement.aTimeout = new Array();
				}
				
				oElement.aTimeout.push(window.setTimeout(function() {
					this.select('ul').invoke('hide');
					
					this.fire('display:image', {
						display	:	true
					});
				}.bind(oElement), 1000));
			});

			Event.observe(oItem, 'show:children', function(oEvt) {
				oEvt.stop();
				
				var oElement = Event.findElement(oEvt, 'li.node-level-2');
				var oParent	 = oElement.up('ul');
				
				oElement.select('ul').invoke('show');

				oElement.siblings().each(function(oSibling) {
					oSibling.select('ul').invoke('hide');
				});
				
				if (oParent.aMouseOverTimeout) {
					oParent.aMouseOverTimeout.each(function(iTimeout) {
						window.clearTimeout(iTimeout);
					});
				}
				
				if (oParent.aMouseStayedTimeout) {
					oParent.aMouseStayedTimeout.each(function(iTimeout) {
						window.clearTimeout(iTimeout);
					});
				}
				
				oParent.aMouseStayedTimeout = new Array();
				oParent.aMouseOverTimeout = new Array();
				
				if (oElement.aTimeout) {
					oElement.aTimeout.each(function(iTimeout) {
						window.clearTimeout(iTimeout);
					});
				}
				
				oElement.aTimeout = new Array();

				oElement.fire('display:image', {
					display	:	false
				});
			});
			
			oItem.select('li').each(function(oSub) {
				Event.observe(oSub, 'mouseover', function(oEvt) {
					oEvt.stop();
					
					Event.element(oEvt).fire('show:children');
				});
				
				Event.observe(oSub, 'mouseout', function(oEvt) {
					oEvt.stop();
					
					Event.element(oEvt).fire('hide:children');
				});
			});
		});
	},

	startRotation	:	function()
	{
		$('horizonmenu').fire('stop:rotation');
		
		
		$$('ul#horizonmenu li.navigation-node.aktiv').first().select('ul').first().show();
		
		if(bRotationOn == false)
		{
			return;
		}

		this.iRotationTimeout = window.setTimeout(function() {
			var oNext = $$('ul#horizonmenu li.navigation-node.aktiv').first().next();
			
			oNext = oNext != null ? oNext : $$('ul#horizonmenu li.navigation-node').first();
			
			oNext.fire('show:node', {
				node : oNext
			});
			
			Navigation.startRotation();
		}, Navigation.iRotationDelay);
	}
};
// Blendet unter anderem das Social BookmarkTool ein und aus
function toggleObject(obj) {
	var el = document.getElementById(obj);
	if ( el.style.display != 'block' ) {
		el.style.display = 'block';
	}	else {
		el.style.display = 'none';
	}
}

// Blendet die Bereichsbilder und den Default Text ein und aus
function toggleIntro(obj) {
	var m1 = document.getElementsByName('menuvisual')[0];
	var m2 = document.getElementsByName('menuvisualdefault')[0];
	if ( obj == 'on' ) {
		m2.style.display = 'block';
		m1.style.display = 'none';
	}	else {
		m1.style.display = 'block';
		m2.style.display = 'none';
	}
}

// HovverEffekt über die ReiterNavigation
function hoverMainMenu(sColorClass)
{
	var sElReiter = document.getElementById("reiter");

	var sErg = sElReiter.className.match(/reiterzahl-./);
	if (sErg)
	  if (sColorClass)
		  sElReiter.className = sErg + ' bg-' + sColorClass;
	  else
	    sElReiter.className = sErg;
	else
	  if (sColorClass)
	    sElReiter.className = 'bg-' + sColorClass;
	  else
	    sElReiter.className = '';
}

// Wechselt Label Texte um
function toggleText(sTextDefault, sTextSwich, sElId)
{
	var sElText = document.getElementById(sElId);
	if (sElText.innerHTML == sTextDefault)
	  sElText.innerHTML = sTextSwich;
	else
	  sElText.innerHTML = sTextDefault;
}

// Rotation in der Navigation
var iReload_after = 4000;
var iCurrentNaviEntry = 1;
var iLastNaviEntry = 0;
var bRun = true;
var tTimer = '';

function adjustTextArea(iNaviEntry)
{
	if (document.getElementsByName('text'+iCurrentNaviEntry)[0])
	{
		if (iNaviEntry != '')
		{
			var iHeight = $('horizonmenu').getHeight();
			$('text'+iNaviEntry).setStyle({height: (iHeight-4)+"px"});
		}
	}
}

function activateNaviEntry()
{
	Navigation.initialize();
}

function toggleEntry(iNaviEntryId)
{}

function toggleSubEntry(iEntryId, iSubEntryId)
{}

function pauseRotation(bDeactivateLastNaviEntry, iNaviEntryId)
{}

function startRotationAgain()
{
	bRun = true;
}

