startList = function() {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("nav");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {	
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
				  this.className=this.className.replace
				        (" over", "");
			   }
			 }
	  	}
	}

	// Styling Subnavigation on mouseover/mouseout for previous item and actual item
	$$('ul.sub li').each(function(li) {
	 	// mouseover
	 	li.addEvent('mouseenter', function(el) { 
	 		// Only act, if the item is not selected
			var elclass=el.getProperty('class');
			//alert(elclass);
			if (elclass=='off' || elclass=='off sep'){
				// Get the index out of the rel-attribute
				var rel=el.getProperty('rel');
				// Set style for current item
				el.setStyle('border-right', '1px solid #FFFFFF');
				// We only need to set a state if rel > 0
				if (rel > 0){
					// id consists of parent_id-item_id
					var combinedid=el.getProperty('id');
					// backup the properties of the element
					backupelement=el.clone(true, true);
					setBorderState(combinedid, rel, 'off');
				}
			}
		}.pass(li));
	 	//mouseout
		li.addEvent('mouseleave', function(el) { 
			// Only act, if the item is not selected
			var elclass=el.getProperty('class');
			// Get the index out of the rel-attribute
			var rel=el.getProperty('rel');
			// Only set borders it the actual item is not the clicked one 
			if (elclass=='off' || elclass=='off sep'){
				// Get the rel-value from the cookie
				var cookierel=Cookie.get('rel');
				var prevrel=cookierel-1;
//				alert(cookierel);
//				alert(prevrel);
//				alert(rel);
				//if (prevrel != rel){
					//alert('prev'+prevrel);
					// Set style for current item
					el.setStyle('border-right', '1px solid #990000');
				//}
				// We only need to set a state if rel > 0
				if (rel > 0){
					// id consists of parent_id-item_id
					var combinedid=el.getProperty('id');
					setBorderState(combinedid, rel, 'on');
				}
			}
		}.pass(li));
		// click
		li.addEvent('click', function(li) {
			// id consists of parent_id-item_id
			var combinedid=li.getProperty('id');
			// Get the index out of the rel-attribute
			var rel=li.getProperty('rel');
			// save combined id and rel to to cookie
			Cookie.set('combinedid', combinedid);
			Cookie.set('rel', rel);
			// now act, if the item is selected
			var elclass=li.getProperty('class');
			//alert(elclass);
			if (elclass=='on' || elclass=='on sep'){
				// We only need to set a state if rel > 0
				if (rel > 0){
					setBorderState(combinedid, rel, 'off');
				}
			}
		}.pass(li));
		// id consists of parent_id-item_id
		var combinedid=li.getProperty('id');
		// Get the index out of the rel-attribute
		var rel=li.getProperty('rel');
		// save combined id and rel to to cookie
		//Cookie.set('combinedid', combinedid);
		//Cookie.set('rel', rel);
		// now act, if the item is selected
		var elclass=li.getProperty('class');
		//alert(elclass);
		if (elclass=='on' || elclass=='on sep'){
			// We only need to set a state if rel > 0
			if (rel > 0){
				setBorderState(combinedid, rel, 'off');
			}
		}
	});
}

// Sets the border for the
function setBorderState(combinedid, rel, state){
	//alert(combinedid);
	// Split the ids to parentid and itemid
	var identifiers=combinedid.split("-");
	var previousrel=rel-1;
	var elementstring='#'+identifiers[0]+' li[rel='+previousrel+']';
	// Get list element to style
	$$(elementstring).each(function(li){
		// Get class
		var actualclass=li.getProperty('class'); 
		// Do nothing if the menu item is actually selected
		if (actualclass!="on" && actualclass!="on sep"){
			//alert("actualclass: "+ actualclass);
			//alert(state);
			var lid=li.getProperty('id');
			lid='#'+lid;
			if (state=='off'){
				$$(lid).setStyle('border-right', '1px solid #FFFFFF');
			}else if(state=='on'){
				$$(lid).setStyle('border-right', '1px solid #990000');
			}
		}
	});
}

window.onload=startList;

//window.addEvent('domready', function() {
//var counter = 0;
//$$('ul.sub').each(function(li) {
//	//var liclass = this.get('class');
//	var rel=li.getProperty('class');
//	//var extension = src.substring(src.lastIndexOf('.'),src.length)
//	li.addEvent('mouseenter', function() { 
//		alert(class)
//	});
//	li.addEvent('mouseleave', function() { 
//		alert('over')
//	});
//	counter++;
//});
//});
