function alertmsg() {
  alert("こんにちは！");
}

function show(e) { //見える状態
  var element = (e.target||ev.srcElement);
  element.style.backgroundColor = "white";
}

function hide(e){//隠す
  var element = (e.target||ev.srcElement);
  element.style.backgroundColor = "red";
}

function addAll() { //配列の作成
  var i, item; //verで宣言
  var checks = document.getElementsByTagName("span"); //cheksにspanの要素を取得
  //こっから理解できなかった
  for (i=0; i<checks.length; i++) {
    item = checks[i];			//i番目のspanを得る
    if (item.getAttribute("class") == "check") {
      item.addEventListener("click", show, false);	//show()関数を呼ぶ

    }
  }
}
window.onload = addAll;

function show(ev) {
  var allul = document.getElementsByTagName("ul");
  var me = (ev.srcElement||this);
  if (!me.id || !me.id.match(/^top-/i)) {
    return;
  }
  for (var i=0; i<allul.length; i++) {
    u = allul[i];
    if (u.id && u.id.match(/^sub-/))
      u.style.visibility = "hidden";
  }
  me.style.backgroundColor = "#ff8"
  var cld = me.childNodes;
  for (var i=0; i<cld.length; i++) {
    if (cld[i].tagName && cld[i].tagName.match(/ul/i)) {
      cld[i].style.visibility = "visible";
    }
  }
}
function hide(ev) {
  var me = (ev.srcElement||this);
  if (!me.id && !me.id.match(/^top-/i)) {
    return;
  }
  me.style.backgroundColor = "#bb0"
}

function addEvent(elm, ev, f) {
  if (elm.addEventListener) {
    elm.addEventListener(ev, f, false);
  } else if (elm.attachEvent) {
    elm.attachEvent("on"+ev, f);
  } else {
    elm["on"+ev] = f;
  }
}

function sethandler() {
  var ul;
  if (ul=document.getElementById("menu")) {
    c = ul.childNodes;
    for (var i=0; i<c.length; i++) {
      if (c[i].tagName && c[i].tagName.match(/li/i)) {
	addEvent(c[i], "mouseover", show);
	addEvent(c[i], "mouseout", hide);
      }
    }
  }
}
window.onload = sethandler;
