function selPrev() {
	obj = selectedObj;

	if(obj.previousSibling){
		if(obj.previousSibling.getAttribute("child") != "false"){
			
			var loopObj = obj.previousSibling.childNodes[2];
			
			while( loopObj.lastChild.childNodes[2] ){
				if(loopObj.lastChild.childNodes[2].style.display == "block" || loopObj.lastChild.childNodes[2].style.display == ""){
					loopObj = loopObj.lastChild.childNodes[2];
				}
				else{
					loopObj = loopObj;
					break;
				}
   			}

			if(loopObj.style.display == "block" || loopObj.style.display == ""){
				loopObj.lastChild.childNodes[1].focus();
				if(obj.previousSibling.getAttribute("child")) getPath(loopObj.lastChild.getAttribute("path"));
			}
			else{
				obj.previousSibling.childNodes[1].focus();
				if(obj.previousSibling.getAttribute("child")) getPath(obj.previousSibling.getAttribute("path"));
			}
		}
		else{
			obj.previousSibling.childNodes[1].focus();
			if(obj.previousSibling.getAttribute("child")) getPath(obj.previousSibling.getAttribute("path"));
		}
	}
	else if(obj.parentNode.parentNode){
		obj.parentNode.parentNode.childNodes[1].focus();
		if(obj.parentNode.parentNode.getAttribute("child")) getPath(obj.parentNode.parentNode.getAttribute("path"));
	}
}

function selNext() {
	obj = selectedObj;
	if(obj.getAttribute("child") != "false"){
		if(obj.childNodes[2].style.display == "block" || obj.childNodes[2].style.display == ""){
			obj.childNodes[2].firstChild.childNodes[1].focus();
			if(obj.childNodes[2].firstChild.getAttribute("child")) getPath(obj.childNodes[2].firstChild.getAttribute("path"));
		}
		else if(obj.nextSibling){
			obj.nextSibling.childNodes[1].focus();
			if(obj.nextSibling.getAttribute("child")) getPath(obj.nextSibling.getAttribute("path"));
		}
		else if(obj.parentNode.parentNode){
			tmpObj = obj.parentNode.parentNode;
			while (!tmpObj.nextSibling){
				tmpObj = tmpObj.parentNode.parentNode;
	    	}
			tmpObj.nextSibling.childNodes[1].focus();
			if(obj.nextSibling.getAttribute("child")) getPath(tmpObj.nextSibling.getAttribute("path"));
		}
	}
	else if(obj.nextSibling){
		obj.nextSibling.childNodes[1].focus();
		if(obj.nextSibling.getAttribute("child")) getPath(obj.nextSibling.getAttribute("path"));
	}
	else if(obj.parentElement.parentElement){
		tmpObj = obj.parentElement.parentElement
		while (!tmpObj.nextSibling){
			tmpObj = tmpObj.parentElement.parentElement;
	    }
		tmpObj.nextSibling.childNodes[1].focus();
		if(obj.nextSibling.getAttribute("child")) getPath(tmpObj.nextSibling.getAttribute("path"));
	}
}

function setKeys(e){
	if(!selectedObj) return;
	if(e) event = e;
	if(event.keyCode == "37"){
		if(selectedObj.childNodes[2])toggleChild(selectedObj.childNodes[2],selectedObj.childNodes[0]);
	}
	else if(event.keyCode == "38") selPrev();
	else if(event.keyCode == "39"){
		if( selectedObj.childNodes[2] )toggleChild(selectedObj.childNodes[2],selectedObj.childNodes[0]);
	}
	else if(event.keyCode == "40") selNext();
	else if(event.keyCode == "13" || event.keyCode == "32" ) window.top.mainWin.location = selectedObj.getAttribute("url");
}

