$(document).ready(function(){
  if($('#signup_register_personal_form').length){
    $.getScript('/SignUp/signup.js');
  }

$( ".ef-group-key" ).click(function( e ){
            eFront.Modal({
                size: "md2",
                url: $.fn.efront( "url", { ctg: "groups", op: "group_key" } )
            });
        });

 var fscLink = $('<div class="pull-left" style="position:relative; font-size:14px; font-weight:700; "><a target="_blank" href="http://www.fsc-deutschland.de" style="color:white;">FSC Germany</a></div>');
  var div = $('<div style="width: 1200px; height: 20px; margin: 0px auto;"></div>');
  
  
  $('#topBar').append(div);
  div.append(fscLink);
  
  var termLink = $('a[data-title="Terms and Conditions"]');
  // termLink.attr("href", termLink.attr("href").replace("lang", "de_" + $("html").attr("lang")));
  termLink.attr("href", "https://fsc-new.clickandlearn.at/eTraining-Platform_Terms-and-Conditions_de_de.pdf");
  $('<div class="pull-left" style="position:relative; font-size:14px; margin-left: 10px;"></div>').append(termLink).insertAfter(fscLink);
  var privacyLink = $('a[data-title="Privacy Policy"]');
  $('<div class="pull-left" style="position:relative; font-size:14px; margin-left: 10px;"></div>').append(privacyLink).insertAfter(termLink.parent());
  $("a[data-title=Contact]").attr('target','_self');
  $('<div class="pull-left" style="position:relative; font-size:14px; margin-left: 10px;"></div>').append($("a[data-title=Contact]")).insertAfter(fscLink);
  $('<div class="pull-left" style="position:relative; font-size:14px; font-weight:700; margin-left: 10px;"></div>').append($('<span style="color: white;">|</span>')).insertAfter(fscLink);

checkLangReady();

var $accounts = $( ".container ul.nav.navbar-nav li > a.ef-switch-account" );

        $accounts.on('click', function(event) {
            if (!$(this).data('id')) {  //prevent self-switching
                return;
            }

            var ending = window.location.hostname + '/';

            if (location.toString().slice(-ending.length) === ending) { //in case there is no ctg  (http://domain)
                parent.location = $.fn.efront('url', { 'switch_account': $(this).data('id') }, location.toString() + 'start');
            } else {
                parent.location = $.fn.efront('url', { 'switch_account': $(this).data('id') }, location.toString())
            }
        });
});

$('a.ef-navbar-logo img').attr('src', $('a.ef-navbar-logo img').attr('src').replace('small', 'large'));

function langReady(){
$('#languageSelection').appendTo($('#languageSelection').siblings());
}

function checkLangReady() {
  if(!$('#languageSelection .account-link').length){
  	setTimeout(function(){checkLangReady();}, 200);  
  }else{
  	langReady();
  }
}