document.aTagPositions = [];
document.aTagActive = -1;
document.marker = null;
document.markerDiv = null;
document.targetPos = null;
document.currMarkerPos = null;
document.intervalID = null;

function setSubnavMarker() {
	var isIEMac = (navigator.platform.toLowerCase().indexOf("mac") != -1 && navigator.appName.toLowerCase().indexOf("microsoft") != -1);
	if (!document.getElementById || !document.getElementsByTagName) { return; }
	document.markerDiv = document.getElementById("subnav_marker");
	document.marker = document.markerDiv.getElementsByTagName("img")[0];
	var subNav = document.getElementById("subnav");
	if (!document.marker || !document.markerDiv || !subNav) { return; }
	var aTags = subNav.getElementsByTagName("a");
	if (!aTags || aTags.length == 0) { return; }
	for (var i = 0; i < aTags.length; i++) {
		document.aTagPositions[document.aTagPositions.length] = Math.min(Math.max(Math.round(aTags[i].offsetLeft + (aTags[i].offsetWidth / 2) - 19), 0), document.markerDiv.offsetWidth - 38) + (isIEMac ? 9 : 0);
		if (aTags[i].className == "active") { document.aTagActive = i; }
		aTags[i].myNum = i;
		aTags.onmouseover = handleRollover;
	}
	if (document.aTagPositions.length == 0 || document.aTagActive == -1) { return; }
	// Ab hier nur wenn ein aktiver Menüpunkt existiert (sonst kein Pfeil)
	positionSubnavMarker(document.aTagActive);
	// Auf Mac IE den Rollover deaktivieren, da dort komisches passiert...
	if (!isIEMac) {
		for (var i = 0; i < aTags.length; i++) {
			aTags[i].myNum = i;
			aTags[i].onmouseover = handleRollover;
			aTags[i].onmouseout = handleRollout;
		}
	}
}

function startSlideSubnavMarker(num) {
	document.targetPos = document.aTagPositions[num];
	if (document.intervalID == null) {
		document.intervalID = window.setInterval("slideSubnavMarker()", 50);
	}
	slideSubnavMarker();
}

function slideSubnavMarker() {
	var offset = Math.ceil(Math.abs(document.targetPos - document.currMarkerPos) / 5);
	var newPos = document.currMarkerPos + (document.currMarkerPos > document.targetPos ? -offset : offset);
	if (Math.abs(document.targetPos - newPos) < 2) { 
		// Fertig
		newPos = document.targetPos;
		window.clearInterval(document.intervalID);
		document.intervalID = null;
	}
	document.currMarkerPos = newPos;
	document.marker.style.marginLeft = newPos + "px";
}

function positionSubnavMarker(num) {
	document.targetNum = num;
	// beim ersten Aufruf direkt setzen
	var markerLeft = document.aTagPositions[num];
	document.marker.style.display = "inline";
	document.marker.style.marginLeft = markerLeft + "px";
	document.currMarkerPos = markerLeft;
}

function handleRollover(ev) {
	startSlideSubnavMarker(this.myNum);
}

function handleRollout(ev) {
	startSlideSubnavMarker(document.aTagActive);
}