// JavaScript Document

	// var openedSubmenuChildId = "sport_submenu_chess";

	
	function initMenu() {
	    YAHOO.util.Event.onContentReady("productsandservices", function () {
	        var oMenu = new YAHOO.widget.Menu("productsandservices", { position: "static" });
			
			
	        oMenu.render();
			addOnClick();
			restoreState();
	    });
	}
	
	function changeState(containerId) {
		var container = document.getElementById(containerId);
		var parentLabel = document.getElementById(containerId+"_parent");
		var ariseContainer = document.getElementById(containerId+"_arise_container");
		if (container.style.display == "none") {
			container.style.display = "block";
			parentLabel.className = "parentitemlabel_opened";
			showAriseContainers();
			ariseContainer.style.display = "none";
			closeSubmenus(containerId);
			
		}
		
	}
	
	function restoreState() {

		if (openedSubmenuChildId) {
			var pos = openedSubmenuChildId.indexOf("_submenu"); 
			var openedSubmenuId = openedSubmenuChildId.substring(0,pos+8);
			var ariseContainer = document.getElementById(openedSubmenuId+"_arise_container");
			ariseContainer.style.display = "none";
			
			document.getElementById(openedSubmenuChildId).className = "choosed_itemlabel";
			document.getElementById(openedSubmenuId).style.display = "block";
			document.getElementById(openedSubmenuId+"_parent").className = "parentitemlabel_opened";
			
		} 
	}
	
	function closeSubmenus(choosedContainerId) {
		var ulList = document.getElementsByTagName("ul");
		
		for(var i=0;i<ulList.length;i++) {
			if (ulList[i].id.substring(ulList[i].id.length-8,ulList[i].id.length) == "_submenu" && ulList[i].id != choosedContainerId) {
				ulList[i].style.display = "none";
				document.getElementById(ulList[i].id+"_parent").className = "parentitemlabel_closed";
			}
		}
	}
	
	function showAriseContainers() {
		var divList = document.getElementsByTagName("div");
		
		for(var i=0;i<divList.length;i++) {
			if (divList[i].id.substring(divList[i].id.length-16,divList[i].id.length) == "_arise_container") {
				divList[i].style.display = "block";
			}
		}	
	}
	
	function addOnClick() {
		var lincList = document.getElementsByTagName("a");
		for(var i=0;i<lincList.length;i++) {
			if (lincList[i].className == "parentitemlabel_closed hassubmenu yuimenuitemlabel" || lincList[i].className == "parentitemlabel_opened") {
				var lincId = lincList[i].id;
				var pos = lincId.indexOf("_parent");
				var containerId = lincId.substring(0,pos);
				lincList[i].onclick = new Function("changeState('"+containerId+"');");
			}
		}	
	}

    function preInit() {
		var ulList = document.getElementsByTagName("ul");
		for(var i=0;i<ulList.length;i++) {
			if (ulList[i].id.substring(ulList[i].id.length-13,ulList[i].id.length) == "_container_ul") {
				var containerId = ulList[i].id.substring(0,ulList[i].id.length-13);
				document.getElementById(containerId).innerHTML = ulList[i].innerHTML;
				
				var aList = ulList[i].getElementsByTagName("a");
				for(var j=0;j<aList.length;j++) {
					aList[j].id = "";
				}
			}	
		}
		initMenu();
	}   