HEModule = new Object ();
with (HEModule) 
{
	var moduleId = "module";
	var moduleNavigationId = "moduleNavigation";
	var moduleIds = ["moduleFirst", "moduleSecond", "moduleThird"];
	var bottomListId = "bottomList";
	var currentPageId = "currentPage";
	var handleId = "handle";
	var closedHeight = 15;
	var shortHeight = 273;
	var longHeight = 434;
	var animationIntervall = 50;
	var animationDistance = 50;
	var currentPageToOpen = null;
	var currentPageNavigationLevel = null;
	// Pfad zum Bild:
	var imagesPath = "/images/nav/";
	var handleImageName = "dropper.png";
}

HEModule.build = function ()
{
	if (!document.getElementById)
	{
		return (false);
	}
	HEModule.buildHeader ();
	HEModule.buildNavigation ();
	if (typeof (initialHeight) != "undefined")
	{
		HEModule.setHeight (initialHeight);
	}
	else if (currentPageToOpen == null && typeof (moduleNavigationList) != "undefined" && moduleNavigationList.length > 0)
	{
		HEModule.setHeight (shortHeight);
	}
	return (false);
}

HEModule.buildHeader = function ()
{
	var module = document.getElementById (moduleId);
	if (typeof (moduleHeader) != "undefined" && moduleHeader != "")
	{
		var h2Element = document.createElement ("h2");
		h2Element.appendChild (document.createTextNode (moduleHeader.linkText));
		h2Element.onclick = function ()
		{
			HEModule.toggleHeight ();
			return (false);
		};
		module.appendChild (h2Element);
	}
}

HEModule.buildNavigation = function ()
{
	function createUlList (navigationList, navigationLevel)
	{
		var ulElement = document.createElement ("ul");
		for (var i = 0; i < navigationList.length; i++)
		{
			var liElement = document.createElement ("li");
			var aElement = document.createElement ("a");
			aElement.appendChild (document.createTextNode (navigationList[i].linkText));
			if (navigationList[i].opensSubNavigation)
			{		
				aElement.setAttribute ("href", "#");
				aElement.onclick = function ()
				{
					HEModule.navigationClick (this, navigationLevel);
					return (false);
				};
				liElement.appendChild (aElement);
				ulElement2 = createUlList (navigationList[i].moduleNavigationList, navigationLevel + 1);
				liElement.appendChild (ulElement2);			
			}
			else if (navigationList[i].horizontalLine)
			{
				liElement.className = "line";
			}
			else
			{
				aElement.setAttribute ("href", navigationList[i].linkUrl);
				aElement.onClick = function ()
				{
					checkTrack (navigationList[i].linkUrl);
				}
				liElement.appendChild (aElement);
			}
			if (navigationList[i].isCurrentPage)
			{
				aElement.id = currentPageId;
				if (navigationLevel > 1)
				{
					currentPageToOpen = aElement;
					currentPageNavigationLevel = navigationLevel;
				}
			}
			ulElement.appendChild (liElement);
		}	
		return (ulElement);
	}

	var module = document.getElementById (moduleId);
	if (typeof (moduleNavigationList) != "undefined" && moduleNavigationList.length > 0)
	{
		var divElement = document.createElement ("div");
		divElement.id = moduleNavigationId;
		var ulElement = createUlList (moduleNavigationList, 1);
		ulElement.id = moduleIds[0];
		divElement.appendChild (ulElement);
		var ulElement2 = createUlList (bottomNavigationList, 0);
		ulElement2.id = bottomListId;
		divElement.appendChild (ulElement2);
		var aElement = document.createElement ("a");
		var imgElement = document.createElement ("img");
		imgElement.id = handleId;
		imgElement.setAttribute ("src", imagesPath + handleImageName);
		aElement.appendChild (imgElement);
		aElement.setAttribute ("href", "#");
		aElement.onclick = function ()
		{
			HEModule.toggleHeight ();
			return (false);
		};
		divElement.appendChild (aElement);
		module.appendChild (divElement);
		if (currentPageToOpen != null)
		{
			if (currentPageNavigationLevel > 2)
			{
				currentPageToOpen = currentPageToOpen.parentNode.parentNode.parentNode.getElementsByTagName ("a")[0];
				currentPageNavigationLevel = currentPageNavigationLevel - 1;
			}
			HEModule.openModuleNavigation (currentPageToOpen, currentPageNavigationLevel);
		}
	}
}
	
HEModule.navigationClick = function (aElement, navigationLevel)
{
	var currentModule = document.getElementById (moduleIds[navigationLevel]);
	if (aElement.parentNode == currentModule)	
	{
		HEModule.closeModuleNavigation (navigationLevel - 1);
	}
	else
	{
		HEModule.openModuleNavigation (aElement, navigationLevel);
	}
	aElement.blur ();
}

HEModule.openModuleNavigation = function (aElement, navigationLevel)
{
	HEModule.closeModuleNavigation (0);
	aElement.parentNode.id = moduleIds[navigationLevel];
	if (navigationLevel > 1)
	{
		aElement.parentNode.parentNode.parentNode.id = moduleIds[1];
	}
	HEModule.setHeight (longHeight);
}

HEModule.closeModuleNavigation = function (navigationLevel)
{
	var moduleFirst = document.getElementById (moduleIds[navigationLevel]);
	liElements = moduleFirst.getElementsByTagName ("li");
	for (var i = 0; i < liElements.length; i++)
	{
		if (liElements[i].nodeType == 1 /* Node.ELEMENT_NODE */ && liElements[i].tagName == "LI")
		{
			liElements[i].id = null;
		}
	}
}

HEModule.toggleHeight = function ()
{
	var moduleNavigation = document.getElementById (moduleNavigationId);
	var moduleNavigationHeight = parseInt (moduleNavigation.style.height);
	if (moduleNavigationHeight == closedHeight)
	{
		HEModule.setHeight (longHeight);

		// Bugfix fuer Internet Explorer :-(
		var ua = navigator.userAgent.toLowerCase (); 
		if (ua.indexOf ("msie") != -1 && ua.indexOf ("opera") == -1 && ua.indexOf ("webtv") == -1)  
		{
                        moduleNavigation.style.backgroundColor = "#ffffff";
			//moduleNavigation.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + imagesPath + "bg_module2.png',sizingMethod='scale')";
		}
		// /Bugfix

	}
	if (moduleNavigationHeight == longHeight || moduleNavigationHeight == shortHeight)
	{
		HEModule.setHeight (closedHeight);
	}
}

HEModule.setHeight = function (newHeight)
{
	var moduleNavigation = document.getElementById (moduleNavigationId);
	var moduleFirst = document.getElementById (moduleIds [0]);
	var bottomList = document.getElementById (bottomListId);
	var currentHeight = parseInt (moduleNavigation.style.height);
	if (newHeight - currentHeight > animationDistance)
	{
		moduleNavigation.style.height = (currentHeight + animationDistance) + "px";
		window.setTimeout ("HEModule.setHeight (" + newHeight + ")", animationIntervall);
	}
	else if (currentHeight - newHeight > animationDistance)
	{
		moduleNavigation.style.height = (currentHeight - animationDistance) + "px";
		window.setTimeout ("HEModule.setHeight (" + newHeight + ")", animationIntervall);
	}
	else
	{
		moduleNavigation.style.height = newHeight + "px";

		// Bugfix fuer Internet Explorer :-(
		var ua = navigator.userAgent.toLowerCase (); 
		if (ua.indexOf ("msie") != -1 && ua.indexOf ("opera") == -1 && ua.indexOf ("webtv") == -1)  
		{
			if (newHeight == closedHeight)
			{
                                moduleNavigation.style.backgroundColor = "#ffffff";
				//moduleNavigation.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + imagesPath + "bg_module_IE.png',sizingMethod='scale')";
			}
		}
		// /Bugfix

	}
	if (newHeight < shortHeight)
	{
		moduleFirst.style.visibility = "hidden";
		bottomList.style.visibility = "hidden";
	}
	else
	{
		moduleFirst.style.visibility = "visible";
		bottomList.style.visibility = "visible";
	}
}