document.addEventListener("DOMContentLoaded", function() {

    // Add JS class
    document.querySelector('body').classList.add('js');

    // Create the dropdown base
    var select = document.createElement("select");

    // Create default option "Go to..."
    var opt = document.createElement("option")
    opt.setAttribute("selected", "selected")
    opt.setAttribute("value", "")
    opt.innerHTML = "Aller à ...";
    select.appendChild(opt);

    // Populate dropdown with menu items
    [].forEach.call(document.querySelectorAll('nav.menu a'), function(el) {
        var opt = document.createElement("option");
        opt.setAttribute("value", el.href)
        opt.innerHTML = el.text;
        select.appendChild(opt);
    });

    // To make dropdown actually work
    // To make more unobtrusive: http://css-tricks.com/4064-unobtrusive-page-changer/
    select.addEventListener('change', function(el) {
      window.location = select.value
    });

    // Add select to menuWrapper
    document.querySelectorAll('nav.menu')[0].appendChild(select);
});