require.config({
  paths: {
    jwplayer: "../../attachment/xwiki/Macros/JWPlayer/jwplayer"
  },
  shim: {
    jwplayer: {
      exports: 'jwplayer'
    }
  }
});
require(['jQueryNoConflict', 'jwplayer'], function($, jwplayer) {
  jwplayer.key="QowE9R/MhMc1H2U6HxMlLTxvbtbk+uhwkexhBQ==";

  var init = function(event, data) {
    var container = $((data && data.elements) || document);
    container.find('.jwplayer').each(function(index) {
      var options = {
        file: $(this).attr('data-source'),
        autostart: $(this).hasClass('autostart'),
        repeat: $(this).hasClass('repeat')
      };
      var width = $(this).attr('data-width');
      width && (options.width = width);
      var height = $(this).attr('data-height');
      height && (options.height = height);
      this.id = this.id || ('jwplayer' + index);
      jwplayer(this.id).setup(options);
    });
  };

  $(document).on('xwiki:dom:updated', init);
  $(init);
});
