function setup() {
  var el=document.getElementById('title');
  el.textContent=g_dir.replace('_',' ');
  g_score=0;
  g_count=0;
  g_used=[];
  next();
}
function klick(el) {
  var el0=document.getElementById(g_answer_id);
  el0.style.backgroundColor='palegreen';
  var id=el.id;
  if (id==g_answer_id) {
    g_score++;
    var el1=document.getElementById('score');
    el1.textContent='Score: '+g_score+' / 5';
    setTimeout(next,1000);
  } else {
    el.style.backgroundColor='red';
    setTimeout(next,3000);
  }
}
function next() {
  reset();
  if (g_count<5) {
    g_count++;
    unused();
    g_used.push(g_ind[0]);
    var el=document.getElementById('pic');
    el.src=g_dir+'/'+g_ind[0]+'.jpg';
    g_answer_id=Random(5)
    for (var i=1;i<6;i++) {
      var el=document.getElementById(i);
      var ind=g_ind[i];
      if (i==g_answer_id) ind=g_ind[0];
      el.textContent=g_pics[ind];
    }
  } else {
    finale();
  }
}
function unused() {
  Shuffle(g_ind);
  var ind=g_ind[0];
  var ok=true;
  for (var i=0;i<g_used.length;i++) {
    if (ind==g_used[i]) ok=false;
  }
  if (!ok) unused();
}
function reset() {
  Hide('pic');
  for (var i=1;i<6;i++) {
    var el=document.getElementById(i);
    el.style.backgroundColor='beige';
  }
}
function finale() {
  var el=document.getElementById('main');
  el.style.display='none';
  for (var i=0;i<5;i++) {
    var el=document.getElementById('e'+i);
    el.src=g_dir+'/'+g_used[i]+'.jpg';
  }
  var el=document.getElementById('end');
  el.style.display='flex';
}
