<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/flag-icon-css/2.6.0/css/flag-icon.css">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script>
  $(function() {    
    /*setup multi-languange */
    var defaultLanguage = 'no';
    var lang = location.pathname.split("/")[1];
    /*set default language for homepage or pages without language prefix */ 
    if (lang == "" || lang.length > 2 ){
      var lang = defaultLanguage;
    }
    $('a[href="/"]').parents('.folder,.collection,.page-collection,.index,.external-link,.external').addClass('nav lang-'+defaultLanguage+'');
    $('nav a:link').each(function (){
      var langType = $(this).attr('href').split("/")[1];
      $(this).parents('.folder,.collection,.page-collection,.index,.external-link,.external').addClass('nav lang-'+langType+'');
    });
    $('.nav:not(".lang-'+lang+'")').remove();

    /*setup language switcher*/
    $('#header').prepend('<div class="language"><a href="/en/home" class="lang-en"><span class="flag-icon flag-icon-gb"></span></a> <a href="/no/hjem/" class="lang-no"><span class="flag-icon flag-icon-no"></span></a></div>');

    /*setup URL reroute for matching langauge page*/
    var loc = window.location.href;
    if (/acerca/.test(loc)) {
      $("a.lang-en").attr("href", "/en/about");
    }
    if (/about/.test(loc)) {
      $("a.lang-no").attr("href", "/no/om/");
    }
  });
</script>