/*
Milisekunden, die die Navigation verz?gert ausgeblendet wird
*/
var delayMs = 2000;
var currentListPoint = -1;

var holdStatus = false;

var triggerCount = 0;
var hoverCheck = false;

var curPath = false;

var navID = "mainNavi";



function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

/*
addLoadEvent(function() {
	var linkTags = document.getElementsByTagName('a');
  for(linkTagsCounter = 0; linkTagsCounter < linkTags.length; linkTagsCounter++) {
  	linkTags[linkTagsCounter].firstChild.select;
  }
});
*/

addLoadEvent(setCurrent);
addLoadEvent(function() {
    
	var mainNavi = document.getElementById(navID);
	var listPoint = document.getElementById(navID).getElementsByTagName("li")[0];
	var counter = 0;
	
	
	document.getElementById("nav").onmouseout = function() {
		delayReset();
	}
	
	document.getElementById("nav").onclick = function() {
		holdReset();
		document.getElementById("nav").onmouseout = "";
	}
	
	document.getElementById("nav").onmouseover = function() {
		holdReset();
	}
	
				
	while (listPoint != null ) {
		
		//nur LI Tag
		if(listPoint.nodeName != "LI") {
			listPoint = listPoint.nextSibling;	
			continue;
		}
		
		if(isCurrentLI(counter)) {
			listPoint.onmouseover = function() {
				Reset(false);
				this.className = 'current';
				
				
			}// ende onmouseover
		}else if (isInRootLineLI(counter)) {
			listPoint.onmouseover = function() {
				Reset(false);				
				this.className = 'curPath';			
			} // ende onmouseover
			
		} else {
			listPoint.onmouseover = function() {
				Reset(false);
				this.className = 'curPath';
				displayTeaser(this.id);
			}
			
			listPoint.onmouseout = function() {
				Reset(false);
				this.className = 'curPath';
				hideTeaser(this.id);
			}
				
		}
		counter++;
		listPoint = listPoint.nextSibling;		
	
		
	}
	
});

function displayTeaser(id) {
	
	if(!document.getElementById("uid1")) {
		return;
	}
	
	document.getElementById("teaserContent").style.display = "none";
	switch(id) {
		case "link_3":
			document.getElementById("teaserContentLink1").style.display = "block";
			break;
		case "link_4":
			document.getElementById("teaserContentLink2").style.display = "block";
			break;
		case "link_5":
			document.getElementById("teaserContentLink3").style.display = "block";
			break;
		case "link_6":
			document.getElementById("teaserContentLink4").style.display = "block";
			break;
		case "link_7":
			document.getElementById("teaserContentLink5").style.display = "block";
			break;
		case "link_133":
			document.getElementById("teaserContentLink6").style.display = "block";
			break;
		default:
			
	}
}

function hideTeaser(id) {
	
	if(!document.getElementById("uid1")) {
		return;
	}
	
	switch(id) {
		case "link_3":
			document.getElementById("teaserContentLink1").style.display = "none";
			break;
		case "link_4":
			document.getElementById("teaserContentLink2").style.display = "none";
			break;
		case "link_5":
			document.getElementById("teaserContentLink3").style.display = "none";
			break;
		case "link_6":
			document.getElementById("teaserContentLink4").style.display = "none";
			break;
		case "link_7":
			document.getElementById("teaserContentLink5").style.display = "none";
			break;
		case "link_133":
			document.getElementById("teaserContentLink6").style.display = "none";
			break;
		
		default:
	}
	
	document.getElementById("teaserContent").style.display = "block";
}


function isInRootLineLI(counter) {
	var ret = false;
	
	if(currentListPoint == counter && curPath) {
		ret = true;
	}
	return ret;
}

function isCurrentLI(counter) {
	var ret = false;
	
	if(currentListPoint == counter && !curPath) {
		ret = true;
	}
	return ret;
}

/***************************************************************************************************
L?scht alle class-Eigenschaften der Listenpunkte der ersten Hierarchie 
****************************************************************************************************/
function Reset(setCurrent) {
	var listPoint = document.getElementById(navID).getElementsByTagName("li")[0];
	var counter = 0;
	
	while (listPoint != null) {
		
		if(listPoint.nodeName != "LI" ) {
			listPoint = listPoint.nextSibling;
			continue;			
		} 
		
		if(listPoint.lastChild.nodeName == "UL") {
			listPoint.lastChild.style.display = "none";
		}
		
		listPoint.className = '';
		
		if (setCurrent && isCurrentLI(counter)) {
			listPoint.className = 'current';
		}
		
		if (setCurrent && isInRootLineLI(counter)) {
			listPoint.className = 'curPath';
		}
		
		if (setCurrent && (isInRootLineLI(counter) || isCurrentLI(counter))) {
			if(listPoint.lastChild.nodeName == "UL") {
				listPoint.lastChild.style.display = "block";
			}			
		}
		
		counter++;
		listPoint = listPoint.nextSibling;
	}
	
}
//Men?punkt befindet sich in der Rootline, ist aber nicht die aktuelle Seite


/***************************************************************************************************
Ermittelt den (statischen) aktuellen Navigationspunkt 
und speichert die Position in der globalen Variablen currentListPoint.
Der Aufruf sollte direkt nach dem Laden der Seite erfolgen.
****************************************************************************************************/
function setCurrent() {
	var listPoint = document.getElementById(navID).getElementsByTagName("li")[0];//firstChild;
	var counter = 0;
	
	while (listPoint != null) {
		
		if(listPoint.className == 'current' || listPoint.className == 'curPath') {
			currentListPoint = counter;
			curPath = listPoint.className == 'curPath'?true:false;
			counter++;
		} else if(listPoint.nodeName == "LI" ) {
			counter++;
		}
		listPoint= listPoint.nextSibling;
	}
}

function holdReset() {
    hoverCheck = true;
}

function delayReset() {
    hoverCheck = false;
    if (triggerCount <= 10) { triggerCount++; setTimeout('tryReset()',delayMs); }
}

function tryReset() {
    triggerCount--;
	setCurrent = true
    if (triggerCount == 0 && !hoverCheck) { 
		Reset(setCurrent); 
	}
}

/*************** IFRAME RESIZE **************************/
window.onresize=resize_iframe; 
function resize_iframe()
{
  //resize the iframe according to the size of the

  //window (all these should be on the same line)

  document.getElementById("glu").style.height= parseInt(document.body.clientHeight-document.getElementById("glu").offsetTop-8)+"px";
}
