function languageSelector(culture) { 
  if (!document_loaded) {
    setTimeout("languageSelector('"+culture+"')", 1000);
  } 
  else {
    var country = culture.substr(3,2);

    if ($('language-switch-'+country)) {
      var oldstatus = $('language-switch-'+country).style.display;
    }

    for (x = 1; x <= 0; x++) {
      $('language-switch-'+locales[x]).style.display = 'none';
    }

    if ($('language-switch-'+country)) {
      $('language-switch-'+country).style.display = (oldstatus == 'block') ? 'none' : 'block';
    }
    else {          
      updateForm(culture);
      i18nActiveTab(country);
    }

    // sublanguages weer inklappen indien deze niet bij de huidige culture hoort
    $$('.sublanguages').each(
      function(s, i) {
        if(s.id.substr(14,2) != culture.substr(3,2)) {
          s.style.display = 'none';
        }
        else {
          s.style.display = 'block';
        }
      }
    );

    $$('.sublanguage').each(
      function(s, i) {
        if(s.id.substr(9,5) != culture) {
          s.removeClassName('active');
        }
        else {
          s.addClassName('active');
          s.addClassName('localized');
        }
      }
    );

    currentculture = culture;
  }
}

// Zet het juiste tabje actief
function i18nActiveTab(country) { 
  for (var i = 0; i < languages.length; i++) {
    try {
      var cc = languages[i].substr(3,2);

      var cls = (country == cc) ? 'active' : '';

      if (country == cc) {
        var image = flagname(document.getElementById('language-switch-'+cc+'-flag').style.backgroundImage)+'.gif)';
        document.getElementById('language-switch-'+cc+'-flag').style.backgroundImage = image;
      }
      document.getElementById('language-switch-'+cc+'-tab').className = cls;

    } catch(e) {}
  }
}

function flagname(url) {
  pos = url.lastIndexOf('-off.gif');
  if (pos == -1) {
    pos = url.lastIndexOf('.gif');
  }
  if (pos != -1) {
    url = url.substr(0,pos);
  }
  return url;
}

Array.prototype.in_array = function(p_val) {
  for(var i = 0, l = this.length; i < l; i++) {
    if(this[i] == p_val) {
      return true;
    }
  }
  return false;
}

function translate(text)
{
  // this is just a placeholder so we can add serverside translation logic later
  return text;
}