var modes=["points","temps","survie"];
var diffs=["easy","med","hard"];
var div=document.getElementById('buttons');
size=screen.height/6;
hideAll();
var modeSelected=null;
var diffSelected=null;

var btn_options=document.getElementById("btn_options");
btn_options.width=size/2;

document.getElementById("btn_play").width=size;
document.getElementById("btn_play_des").width=size;
document.getElementById("btn_play").style.display="none";

document.getElementById("btn_high").width=size;

modes.forEach(element => {
    eval("var btn"+element+"= document.getElementById('btn_"+element+"')");
    eval("btn_"+element+".width=size");
    eval("btn_"+element).addEventListener("mousedown",function(e){disp(e);});
    var tab=document.getElementById(element).children;
    for(var i=0;i<tab.length;i++){
        tab.item(i).width=size;
        tab.item(i).addEventListener("mousedown",function(e)
        {
            var tab=document.getElementById("modeSelection").children;
            for(var cpt=1;cpt<tab.length;cpt++)
            {
                var tabChilds=document.getElementById(tab.item(cpt).id).children;
                for(var cptChild=0;cptChild<tabChilds.length;cptChild++)
                {
                    tabChilds.item(cptChild).classList.remove("selected");
                }
            }

            document.getElementById(e.currentTarget.id).classList.add("selected");
            modeSelected= e.currentTarget.id;
            setCookie("modeSelected",modeSelected,30);
            if(modeSelected!=null && diffSelected!=null)
            {
                document.getElementById("btn_play").style.display="inline";
            document.getElementById("btn_play_des").style.display="none";
            }
        });
    }
});

diffs.forEach(element => {
    eval("var btn_"+element+"= document.getElementById('btn_"+element+"')");
    eval("btn_"+element+".width=size");
    eval("btn_"+element).addEventListener("mousedown",function(e)
    {
        diffSelected= e.currentTarget.id.substring(4);
        //setCookie("diffSelected",diffSelected,30);
        var tab=document.getElementById("diff").children;
        for(var cpt=0;cpt<tab.length;cpt++)
        {
            tab.item(cpt).classList.remove("selected");
        }
        document.getElementById(e.currentTarget.id).classList.add("selected");
        if(modeSelected!=null && diffSelected!=null)
        {
            document.getElementById("btn_play").style.display="inline";
            document.getElementById("btn_play_des").style.display="none";
        }
    });
})

function disp(what)
{
    what=what.currentTarget.id.substring(4);
    modes.forEach(element => {
        document.getElementById(element).style.display=what==element ? "flex":"none";
    })
}


    

function hideAll()
{
    document.getElementById("temps").style.display="none";
    document.getElementById("points").style.display="none";
    document.getElementById("survie").style.display="none";
}

function play()
{
    window.location.replace("./game.html?mode="+modeSelected+"&diff="+diffSelected+"&pseudo="+document.getElementById("field_pseudo").value);
}

function goHigh()
{
    window.location.replace("./highscores.php");
}