
function MM_reloadPage(init) {
  //reloads the window if Nav4 resized
  if (init == true) with (navigator) {
    if ((appName == "Netscape") && (parseInt(appVersion) == 4)) {
      document.MM_pgW = innerWidth; document.MM_pgH = innerHeight; onresize = MM_reloadPage;
    }
  }
  else if (innerWidth != document.MM_pgW || innerHeight != document.MM_pgH) location.reload();
}

MM_reloadPage(true);

(function () {

  let langs = "";
  let valueSelected;
  let lengSelected;
  let launchPage;

  $.getJSON("./wrapper/data/langPack.json", function (data) {
    addFlexList(data);
    // addDropDown(data);
  });

  var addDropDown = function (data) {
    $.each(data.languages, function (key, val) {
      options += "<option class='" + (key++) + "' value='" + val + "'>" + val + "</option>"
    });

    launchPage = data.launchPage;
    $("#langSet").children("option").after(options);

    $('select').off('change').on('change', function (e) {
      optionSelected = $("option:selected", this);
      valueSelected = this.value;
      $("#start").attr("disabled", false);
      $(this).blur();
      language = valueSelected
    });

    $("#start").click(function () {
      language = valueSelected;
      updateIndex(language);
      // course_path = "./courses/" + language;
      // var ulrLink = course_path + '/' + launchPage;
      // window.location.replace(ulrLink);
    })
  }

  var addFlexList = function (data) {

    $.each(data.languages, function (key, val) {
      langs += "<div tabindex ='0' class='lang lang_" + (key++) + "' data-lang='" + val + "'>" + val + "</div>"
    });

    launchPage = data.launchPage;

    $("#lang_row").empty()
    $("#lang_row").append(langs);

    setTimeout(function () {
      $('#lang_row .lang').off('keypress').on('keypress', function (e) {
        langSelected($(this))
      });
      $('#lang_row .lang').off('click').on('click', function (e) {
        langSelected($(this))
      });
      $(".langSelector").focus();
    }, 100)
  }

  var langSelected = function (btn) {
    $('#lang_row .lang').removeClass('selected');
    btn.addClass("selected");
    lengSelected = btn.attr('data-lang');
    updateIndex(lengSelected);
  }

})()