/*
	menu_ul V 1.0
	Author : Benoit Raux (http://rauxbenoit.free.fr)
	Usage : Another  JS/CSS menu
*/


function menu_ul_overParent(objElt){
	switch (objElt.className){
		case 'menu_parent_basic':						
			objElt.className = 'menu_parent_over';
		break;
		case 'menu_parent_active':						
			objElt.className = 'menu_parent_active_over';
		break;
		case 'menu_parent_over':
			objElt.className = 'menu_parent_over';			
		break;
		case 'menu_parent_selected':						
			objElt.className = 'menu_parent_selected_over';
		break;
		case 'menu_parent_selected_over':
			objElt.className = 'menu_parent_selected_over';			
		break;
	}
}

function menu_ul_outParent(objElt){
	switch (objElt.className){
		case 'menu_parent_basic':						
			objElt.className = 'menu_parent_basic';
		break;
		case 'menu_parent_active':						
			objElt.className = 'menu_parent_active';
		break;
		case 'menu_parent_active_over':						
			objElt.className = 'menu_parent_active';
		break;
		case 'menu_parent_over':
			objElt.className = 'menu_parent_basic';			
		break;
		case 'menu_parent_selected':						
			objElt.className = 'menu_parent_selected';
		break;
		case 'menu_parent_selected_over':
			objElt.className = 'menu_parent_selected';			
		break;
	}
}

function menu_ul_clickParent(objElt){
	booSon = false;
	objParentNode = objElt.parentNode;
	if (objParentNode.childNodes.length > 0) {
		for (var i=0; i<objParentNode.childNodes.length; i++) {
			var objChild = objParentNode.childNodes[i];
			if (objChild.nodeName == "UL") {
				booSon = true;
				switch (objChild.className){
					case 'menu_son':						
						objChild.className = 'menu_son_open';
						objElt.className = 'menu_parent_selected_over';
					break;
					case 'menu_son_open':
						objChild.className = 'menu_son';
						objElt.className = 'menu_parent_over';
					break;
				}
				break;
			}						
		}		
	}
	if(booSon==false){		
		document.location.href = objElt.href;
	}
}

function menu_ul_overSon(objElt){
	switch (objElt.className){
		case 'menu_son_basic':						
			objElt.className = 'menu_son_over';
		break;
		case 'menu_son_over':
			objElt.className = 'menu_son_over';			
		break;
		case 'menu_son_active':
			objElt.className = 'menu_son_active_over';			
		break;
		case 'menu_son_active_over':
			objElt.className = 'menu_son_active_over';			
		break;
	}
}

function menu_ul_outSon(objElt){
	switch (objElt.className){
		case 'menu_son_basic':						
			objElt.className = 'menu_son_basic';
		break;
		case 'menu_son_over':
			objElt.className = 'menu_son_basic';			
		break;
		case 'menu_son_active':
			objElt.className = 'menu_son_active';			
		break;
		case 'menu_son_active_over':
			objElt.className = 'menu_son_active';			
		break;
	}
}

function menu_ul_clickSon(objElt){
	document.location.href = objElt.href;
}

function menu_ul_prepare(strId){
	objElt = document.getElementById(strId);
	if (objElt.childNodes.length > 0) {
		for (var i=0; i<objElt.childNodes.length; i++) {
			var objParentLi = objElt.childNodes[i];
			if (objParentLi.nodeName == "LI") {
				if (objParentLi.childNodes.length > 0) {
					for (var j=0; j<objParentLi.childNodes.length; j++) {
						var objParentLiChild = objParentLi.childNodes[j];
						//Must find a A in son of LI
						if (objParentLiChild.nodeName == "A") {						
							//test if active page
							if(document.location.href == objParentLiChild.href){
								objParentLiChild.className = 'menu_parent_active';
							} else {
								objParentLiChild.className = 'menu_parent_basic';
							}
							objParentLiChild.onclick = function (){
								menu_ul_clickParent(this);
								return false;
							}
							objParentLiChild.onmouseover = function (){
								menu_ul_overParent(this);
								return false;
							}
							objParentLiChild.onmouseout = function (){
								menu_ul_outParent(this);
								return false;
							}
						}						
						//Is there a son menu (UL) ?
						if (objParentLiChild.nodeName == "UL") {
							objParentLiChild.className = 'menu_son';
							//Must find somme LI with A inside
							if (objParentLiChild.childNodes.length > 0) {
								for (var k=0; k<objParentLiChild.childNodes.length; k++) {
									var objSonLi = objParentLiChild.childNodes[k];
									if (objSonLi.nodeName == "LI") {
										if (objSonLi.childNodes.length > 0) {
											for (var l=0; l<objSonLi.childNodes.length; l++) {
												var objSonA = objSonLi.childNodes[l];
												if (objSonA.nodeName == "A") {
													//Link of Son
													//test if active page
													if(document.location.href == objSonA.href){
														objSonA.className = 'menu_son_active';
														objParentLiChild.className = 'menu_son_open';
														if (objParentLi.childNodes[(j-2)].nodeName=="A"){
															objParentLi.childNodes[(j-2)].className = 'menu_parent_selected';
														}
														
													} else {
														objSonA.className = 'menu_son_basic';
													}
													objSonA.onclick = function (){
														menu_ul_clickSon(this);
														return false;
													}
													objSonA.onmouseover = function (){
														menu_ul_overSon(this);
														return false;
													}
													objSonA.onmouseout = function (){
														menu_ul_outSon(this);
														return false;
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}						
		}		
	}
}
