
//メニュー表示イベント設置
var timerId = false;
if(window.attachEvent){

	window.attachEvent("onload", setMenu);

}else{

	window.addEventListener("load", setMenu ,true);

}


function setMenu()
{
	var list = document.getElementsByClassName("menu");
	if(typeof(list) == "undefined"){
		return;
	}
	
	for(var i=0; i<list.length; i++){
		var menu = list[i];
		var menu_click = false;
		
		if(typeof(menu.start_color) == "undefined"){
			menu.start_color = '#FFE7CF';
		}
		if(typeof(menu.end_color) == "undefined"){
			menu.end_color = '#EBEBEB';
		}
		if(typeof(menu.selected_color) == "undefined"){
			menu.selected_color = '#FF9933';
		}
		if(typeof(menu.menu_click) != "undefined"){
			menu_click = true;
		}
		
		
		for(var j=0; j<menu.childNodes.length; j++){
			var item = menu.childNodes[j];
			item.parentMenu = menu;
			item.onmouseover = on_menu_item;
			item.onmouseout = out_menu_item;
		}
		
		var parent = menu.parentNode;
		for(var j=0; j<parent.childNodes.length; j++){
			if(parent.childNodes[j].className == "menu_button"){
				if(menu_click == true){
					parent.childNodes[j].onclick = on_menu_button;
				}else{
					parent.childNodes[j].onmouseover = on_menu_button;
				}
				parent.childNodes[j].onmouseout = out_menu_button;
			}
		}
	}
}

function on_menu_button()
{
	if(typeof(timerId) != "undefined" && timerId){
		window.clearTimeout(timerId);
		timerId = false;
	}
	
	var list = document.getElementsByClassName("menu");
	for(var i=0; i<list.length; i++){
		var menu = list[i];
		if(this == menu){
			console.warn("同じ");
			return;
		}
		menu.style.display = "none";
	}
	
	for(var i=0; i<this.parentNode.childNodes.length; i++){
		if(this.parentNode.childNodes[i].className == "menu"){
			this.parentNode.childNodes[i].style.display = "block";
		}
	}
}
function out_menu_button()
{
	menu_mouseOut();
}

function on_menu_item()
{
	if(timerId){
		window.clearTimeout(timerId);
		timerId = false;
	}
	
	if(typeof(this.preEffects) != "undefined"){
		this.preEffects.cancel();
	}
	
	//this.style.backgroundColor = '#FF9933';
	this.style.backgroundColor = this.parentMenu.selected_color;
	Element.addClassName(this,"selection");
}

function out_menu_item()
{
	menu_mouseOut();
	
	
	Element.removeClassName(this,"selection");
	this.preEffects = new Effect.Highlight(this, {
				startcolor : this.parentMenu.start_color
				, endcolor : this.parentMenu.end_color
				, restorecolor : this.parentMenu.end_color
			});
}

function menu_mouseOut()
{

	if(timerId){
		window.clearTimeout(timerId);
		timerId = false;
	}
	timerId = window.setTimeout("menuHideAll()",500);
}



function menuHideAll()
{
	var list = document.getElementsByClassName("menu");
	for(var i=0; i<list.length; i++){
		list[i].style.display = "none";
	}
}










