{% if site.app.ios_id %}
  <!-- iTunes Search API -->
  <script>
    $(function() {
      var API_URL = 'https://itunes.apple.com/lookup?id={{ site.app.ios_id }}&callback=?';
      $.getJSON(API_URL, function(res) {
        if (res.results && res.results.length) {
          console.info('App info successfully loaded from Apple');
          var appInfo = res.results[0];
          // App Icon
          var $appIcon = $('.app-icon');
          if ( $appIcon && !$appIcon.attr('src') && appInfo.artworkUrl512 ) {
            $appIcon.attr('src', appInfo.artworkUrl512);
          }
          // App Screenshot
          var $appScreenshot = $('.app-screenshot');
          if ( $appScreenshot && !$appScreenshot.attr('src') && appInfo.screenshotUrls && appInfo.screenshotUrls.length ) {
            $appScreenshot.attr('src', appInfo.screenshotUrls[0]);
          }
        } else {
          console.warn('Unable to load app info from Apple');
        }
      });
    });
  </script>
  <!-- End iTunes Search API -->
{% endif %}
