// The following is Google's code for website translating.
// We are wrapping their div in our own #google-translate-modal though.
// Customize your own at: http://translate.google.com/translate_tools?hl=en

function googleTranslateElementInit() {
  new google.translate.TranslateElement({
    pageLanguage: 'sv',
    autoDisplay: false,
    layout: google.translate.TranslateElement.InlineLayout.SIMPLE
  }, 'google_translate_element');
}

// Integrate Google Analytics

$svjq(function() {
  $svjq('body').append('<div id="google-translate-modal"><div id="google-translate-modal-close"><a href="#">Close</a></div><div id="google_translate_element"></div><p>Use Google to translate the web site. We take no responsibility for the accuracy of the translation.</p></div>');
  $svjq.getScript('//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit');

  // Show hide the modal window when the user clicks a link that goes to
  // translate.google*
  $svjq('a[href^="http://translate.google"]').click(function(e) {
    e.preventDefault();

    if (!$svjq('.goog-te-banner-frame').is(":visible")) {
      var parent = $svjq(this).parent();
      var modal = $svjq('#google-translate-modal');

      parent.css('position', 'relative');
      modal.prependTo(parent.get(0));
      modal.show();
    }

    // Close the translate modal window when the user chooses language
    $svjq('iframe.goog-te-menu-frame').contents().find('a').click(function(e) {
      $svjq('#google-translate-modal').hide();
    });
  });

  $svjq('#google-translate-modal-close').click(function() {
    $svjq('#google-translate-modal').hide();
  });
});

