{% spaceless %}
{% load i18n %}
{% load thumbnail %}
<div>
<div id="{{ player_id }}_embed" class="iri_player_embed">
</div>
<script type="text/javascript">
  /* Redefine a few variables */  
IriSP.jwplayer_swf_path = "{{WEB_URL}}{{LDT_MEDIA_PREFIX}}swf/player.swf";
IriSP.libFiles["defaultDir"] = "{{WEB_URL}}{{LDT_MEDIA_PREFIX}}js/";

if(!IriSP.paths)
	IriSP.paths = {};
if(!IriSP.default_templates_vars)
	IriSP.default_templates_vars = {};
IriSP.paths["imgs"] = "{{WEB_URL}}{{LDT_MEDIA_PREFIX}}css/imgs";
IriSP.default_templates_vars["img_dir"] = IriSP.paths.imgs;

IriSP.platform_url = "{{WEB_URL}}{{BASE_URL}}";
IriSP.user = {
    name: '{{request.user.username}}',
    avatar: '{% thumbnail request.user.get_profile.image "48x48" format="PNG" crop="center" as im %}{{WEB_URL}}{{ im.url }}{% endthumbnail %}',
};

      
var config = {            
    gui: {
        width: {{ player_width }},
        height: 600,  
        container: '{{ player_id }}_embed',
        css: '{{WEB_URL}}{{LDT_MEDIA_PREFIX}}css/LdtPlayer.css',
        default_options: {
            metadata:{
                format:'cinelab',
                src: '{{ json_url }}',
                type:'json'
            },
            width: {{ player_width }},
            cinecast_version: false
        },
        widgets: [
            {
                type: "PolemicWidget",
                height: 50,
                requires: [
                    {
                        type: "TooltipWidget",
                        width: 180,
                        height: 160,
                        metadata : {
                            type:'empty'
                        }
                    }
                ]
            },
            {
                type: "SparklineWidget",
                height: 50
            },
            {
                type: "SliderWidget"
            },
            {
                type: "AnnotationsListWidget",
                container: "annot_media",
                ajax_url: "{% url segment_api_empty %}{% templatetag openvariable %}media{% templatetag closevariable %}/{% templatetag openvariable %}begin{% templatetag closevariable %}/{% templatetag openvariable %}end{% templatetag closevariable %}"
            },
            {
                type: "PlayerWidget",
                mode: "radio"
            },
            {
                type: "SegmentsWidget",
             requires: [
                    {
                        type: "TooltipWidget",
                        width: 180,
                        height: 160,
                        metadata : {
                            type:'empty'
                        }
                    }
                ],
            },
            {
                type: "SliceWidget",
                mode: "radio"
            },            
            {
                type: "ArrowWidget"
            },
            {
                type: "AnnotationsWidget"
            },
            {
                type: "TweetsWidget"
            },
            {
                type: "createAnnotationWidget",
                api_endpoint_template: "{% url annotation_api_empty %}{% templatetag openvariable %}id{% templatetag closevariable %}.json",
                keywords: ["#amateur", "#digital-humanities"]
            },
            {
                type: "SlideShareWidget",
                container: "slides_container"
            }
        ]
    },
      {% if external_url %}
      player:{
          type: {% if "youtube.com" in external_url %}'youtube'{% else %}'dailymotion'{% endif %}, // player type
          height: 300, 
          width: {{ player_width }}, 
          video: '{{ external_url }}'
      },
      {% else %}
      player:{
          type:'jwplayer', // player type
          live: true, 
          height: 300, 
          width: {{ player_width }}, 
          provider: "rtmp" 
      },
      {% endif %}
      modules: [
               { type: "MediaFragment",
                  metadata:{
                 format:'cinelab',
                 src:'{{ json_url }}',
                 type:'json'}
            }]

    };

    IriSP.initPlayer(config, "{{ json_url }}");
</script>
</div>
{% endspaceless %}
