
wbec = {};

wbec.isFirstLoad = function(namesp) {
  var isFirst = namesp.firstLoad === undefined;
  namesp.firstLoad = false;
  return isFirst;
}

window.onload = function() {
  if (!wbec.isFirstLoad(wbec)) {
	  return;
  }
  var hwts = document.querySelectorAll(".wbec .entry .hw_txt,.wbec.dro .dre");
  for (let i = 0; i < hwts.length; i++) {
    var hwt = hwts[i];
    if (hwt.closest(".entry,.dro").querySelectorAll(".vis_w,.uro_def,.def_labels").length > 0) {
      hwt.style.color = "#14599D";
    }
    hwt.addEventListener("click", modeSwitch);
  }
  var snus = document.querySelectorAll(".wbec .sblock .sn_block_num,.wbec .uro .ure");
  for (let i = 0; i < snus.length; i++) {
    var snu = snus[i];
    if (snu.closest(".sblock,.uro").querySelectorAll(".vis_w,.uro_def,.def_labels").length > 0) {
      snu.style.color = "#14599D";
    }
    snu.addEventListener("click", showExamples);
  }
}

function modeSwitch() {
  var flag = true;
  var sds = this.closest(".entry,.dro").querySelectorAll(".sblocks~.dros");
  for (let i = 0; i < sds.length; i++) {
    var sd = sds[i];
    if (sd.style.display === "block") {
      sd.style.display = "none";
      flag = false;
    }
  }
  var vis = this.closest(".entry,.dro").querySelectorAll(".vis_w,.uro_def,.def_labels");
  for (let i = 0; i < vis.length; i++) {
    var vi = vis[i];
    if (vi.style.display === "block") {
      vi.style.display = "none";
      flag = false;
    }
  }
  var hts = this.closest(".entry,.dro").querySelectorAll(".hidden_text");
  for (let i = 0; i < hts.length; i++) {
    var ht = hts[i];
    if (ht.style.display === "inline") {
      ht.style.display = "none";
      flag = false;
    }
  }
  if (flag) {
    for (let i = 0; i < sds.length; i++) {
      var sd = sds[i];
      sd.style.display = "block";
    }
    for (let i = 0; i < vis.length; i++) {
      var vi = vis[i];
      vi.style.display = "block";
    }
    for (let i = 0; i < hts.length; i++) {
      var ht = hts[i];
      ht.style.display = "inline";
    }
  }
}


function showExamples() {
  var vis = this.closest(".sblock,.uro").querySelectorAll(".vis_w,.uro_def,.def_labels");
  for (let i = 0; i < vis.length; i++) {
    var vi = vis[i];
    if (vi.style.display !== "block") {
      vi.style.display = "block";
    } else {
      vi.style.display = "none";
    }
  }
  var hts = this.closest(".sblock,.uro").querySelectorAll(".hidden_text");
  for (let i = 0; i < hts.length; i++) {
    var ht = hts[i];
    if (ht.style.display !== "inline") {
      ht.style.display = "inline";
    } else {
      ht.style.display = "none";
    }
  }
}
