{% if settings.show_multiple_currencies %}
<script src="{{ '//cdn.shopify.com/s/javascripts/currencies.js' }}"></script>
<script src="{{ 'jquery.currencies.min.js' | asset_url  }}"></script>

<script type="text/javascript">
  
  jQuery('.currencies li').on('click', function() {
    
    jQuery('.currency-block').removeClass('opened');
    jQuery('.currencies li').removeClass('active');
    jQuery(this).addClass('active');
    
    var selectedValue = jQuery(this).find('input[type=hidden]').val();
    
    jQuery('.currencies_src option').attr('selected', false);
    jQuery('.currencies_src option[value='+selectedValue+']').attr('selected', true);
    
    Currency.convertAll(Currency.currentCurrency, selectedValue);
    //AT_Main.callPriceSlider();
    
    jQuery('.currency_code').html($(this).find('a span').html());
  });
  
  var shopCurrency = '',
      defaultCurrency = '',
      cookieCurrency = '';
  
  currenciesCallback();
  
  function currenciesCallback (){
    
    {% if settings.currency_format %}Currency.format = '{{ settings.currency_format }}';{% endif %}
     
     shopCurrency = '{{ shop.currency }}';
      
      /* Sometimes merchants change their shop currency, let's tell our JavaScript file */
     Currency.money_with_currency_format[shopCurrency] = {{ shop.money_with_currency_format | strip_html | json }};
     Currency.money_format[shopCurrency] = {{ shop.money_format | strip_html | json }};
    
    
    /* Default currency */
    defaultCurrency = '{{ settings.default_currency }}' || shopCurrency;
    
    /* Cookie currency */
    cookieCurrency = Currency.cookie.read();
    
    /* Fix for customer account pages */
    jQuery('span.money span.money').each(function() {
      jQuery(this).parents('span.money').removeClass('money');
    });
    
    /* Saving the current price */
    jQuery('span.money').each(function() {
      jQuery(this).attr('data-currency-{{ shop.currency }}', jQuery(this).html());
    });
    
    // If there's no cookie.
    if (cookieCurrency == null) {
      if (shopCurrency !== defaultCurrency) {
        Currency.convertAll(shopCurrency, defaultCurrency);
      }
      else {
        Currency.currentCurrency = defaultCurrency;
      }
      Currency.cookie.write(defaultCurrency);
    }
    // If the cookie value does not correspond to any value in the currency dropdown.
    else if (jQuery('[name=currencies]').size() && jQuery('[name=currencies] option[value=' + cookieCurrency + ']').size() === 0) {
      Currency.currentCurrency = shopCurrency;
      Currency.cookie.write(shopCurrency);
    }
      else if (cookieCurrency === shopCurrency) {
        Currency.currentCurrency = shopCurrency;
      }
      else {
        Currency.convertAll(shopCurrency, cookieCurrency);
        
        jQuery('.currencies li').removeClass('active');
        jQuery('.currencies .currency-'+cookieCurrency).addClass('active');
        jQuery('.currency_code').html(jQuery('.currencies .currency-'+cookieCurrency).find('a span').html());
      }
    
    jQuery('.currencies_src').on("change", function(e) {
		
      var newCurrency = jQuery(e.currentTarget).find(':selected').attr('value');
      jQuery('.selected-currency').text(Currency.currentCurrency);
      if($('.templateProduct').length != 0)
     	  updatePricing();

    });
  }
  
  function currenciesCallbackSpecial(id){
    /* Saving the current price */
    jQuery(id).each(function() {
      jQuery(this).attr('data-currency-{{ shop.currency }}', jQuery(this).html());
    });
    
    /* Update currency */
    Currency.convertAll(shopCurrency, Currency.cookie.read(), id, '{{ settings.currency_format }}');
  }
</script>

{% endif %}