/**
 * autor: joachim.kliemann
 */
if (!YAHOO.hmmh) YAHOO.namespace("hmmh");

YAHOO.hmmh.cms = function() {
	
	var activeLink = '';
	var levelBefore = '';
	var nextRequest = false;
	return {
		initNavigation : function() {
			var cmsLink = $D.get('activeCmsLink');
			if(cmsLink == null) {
				return;
			}
			var path = cmsLink.value;
			var basePath = document.getElementById('basePath').value;
			var patharray = path.split("/");
			var linksarray = patharray.slice(3,patharray.length);
			var patharraylength = patharray.length; 
			// Die ersten zwei Einträge im Path sind immer vorgegeben. Also deren Anzahl ist immer 2.
			// Durch das Split mit dem '/' ergeben sich im Array 4 Einträge.
			// Diese 4 Einträge müssen für die Navigationstiefe (weitere Navigationselement-Request) 
			// unberücksichtigt bleiben.
			var pageId = '';
			
			for(var index = 0 ; index < linksarray.length ; index++){
				
				// Ein Request für die Navigation
				if(linksarray[index].length > 0){
					
					pageId = pageId + linksarray[index] +'/';
					activeLink = basePath + pageId;
					levelBefore = basePath + linksarray[(index-1)] +'/'; 
					try{
						FontshopAjaxUtilities.handleNavigation(
					  			activeLink, 
					  			{ callback: handleReturnedHtml, errorHandler: handleErrors, async:false }
						);
					} catch (x) {}
			
					var returnString = getReturnedHtml();
					if(YAHOO.hmmh.cms.trim(returnString).length > 0){
						document.getElementById('submenue'+activeLink).innerHTML = returnString;	
					}
					 
				}
			}
			// Den aktiven in Bold 
			if(document.getElementById(activeLink)){
				document.getElementById(activeLink).style.backgroundColor = 'rgb(219, 223, 222)';
				document.getElementById(activeLink).style.color = 'rgb(0, 0, 0)';
				document.getElementById(activeLink).style.fontWeight = 'bold';	
				document.getElementById('li'+activeLink).style.backgroundColor = 'rgb(219, 223, 222)';
				document.getElementById('li'+activeLink).style.color = 'rgb(0, 0, 0)';
			}
			// und den n�chst �beren/h�heren in Bold grau
			if(document.getElementById(levelBefore)){
				document.getElementById(levelBefore).style.fontWeight = 'bold';
			}
			
			
			
			
		},
	 // trim functions
	 leftTrim : function(txt)
	  {
	    //Match spaces at beginning of text and replace with a null string
	    return txt.replace(/^\s+/,'');
	  },
	  rightTrim : function(txt)
	  {
	    //Match spaces at end of text and replace with a null string
	    return txt.replace(/\s+$/,'');
	  },
	  trim : function(txt)
	  {
	    //Remove spaces at beginning and end of text
	    return(YAHOO.hmmh.cms.leftTrim(YAHOO.hmmh.cms.rightTrim(txt)));
	  }
		
	};

}();
YAHOO.util.Event.on(window, 'load', YAHOO.hmmh.cms.initNavigation, YAHOO.hmmh.cms, true);	

