web/res/metadataplayer/LdtPlayer-core.js
changeset 694 e9400c80e1e4
parent 654 a5977736d2b0
child 719 d0d3a9369f84
--- a/web/res/metadataplayer/LdtPlayer-core.js	Mon Oct 15 14:34:47 2012 +0200
+++ b/web/res/metadataplayer/LdtPlayer-core.js	Tue Oct 02 14:40:14 2012 +0200
@@ -20,11 +20,11 @@
     v2.0.3 (c) Kyle Simpson
     MIT License
 */
-(function(o){var K=o.$LAB,y="UseLocalXHR",z="AlwaysPreserveOrder",u="AllowDuplicates",A="CacheBust",B="BasePath",C=/^[^?#]*\//.exec(location.href)[0],D=/^\w+\:\/\/\/?[^\/]+/.exec(C)[0],i=document.head||document.getElementsByTagName("head"),L=(o.opera&&Object.prototype.toString.call(o.opera)=="[object Opera]")||("MozAppearance"in document.documentElement.style),q=document.createElement("script"),E=typeof q.preload=="boolean",r=E||(q.readyState&&q.readyState=="uninitialized"),F=!r&&q.async===true,M=!r&&!F&&!L;function G(a){return Object.prototype.toString.call(a)=="[object Function]"}function H(a){return Object.prototype.toString.call(a)=="[object Array]"}function N(a,c){var b=/^\w+\:\/\//;if(/^\/\/\/?/.test(a)){a=location.protocol+a}else if(!b.test(a)&&a.charAt(0)!="/"){a=(c||"")+a}return b.test(a)?a:((a.charAt(0)=="/"?D:C)+a)}function s(a,c){for(var b in a){if(a.hasOwnProperty(b)){c[b]=a[b]}}return c}function O(a){var c=false;for(var b=0;b<a.scripts.length;b++){if(a.scripts[b].ready&&a.scripts[b].exec_trigger){c=true;a.scripts[b].exec_trigger();a.scripts[b].exec_trigger=null}}return c}function t(a,c,b,d){a.onload=a.onreadystatechange=function(){if((a.readyState&&a.readyState!="complete"&&a.readyState!="loaded")||c[b])return;a.onload=a.onreadystatechange=null;d()}}function I(a){a.ready=a.finished=true;for(var c=0;c<a.finished_listeners.length;c++){a.finished_listeners[c]()}a.ready_listeners=[];a.finished_listeners=[]}function P(d,f,e,g,h){setTimeout(function(){var a,c=f.real_src,b;if("item"in i){if(!i[0]){setTimeout(arguments.callee,25);return}i=i[0]}a=document.createElement("script");if(f.type)a.type=f.type;if(f.charset)a.charset=f.charset;if(h){if(r){e.elem=a;if(E){a.preload=true;a.onpreload=g}else{a.onreadystatechange=function(){if(a.readyState=="loaded")g()}}a.src=c}else if(h&&c.indexOf(D)==0&&d[y]){b=new XMLHttpRequest();b.onreadystatechange=function(){if(b.readyState==4){b.onreadystatechange=function(){};e.text=b.responseText+"\n//@ sourceURL="+c;g()}};b.open("GET",c);b.send()}else{a.type="text/cache-script";t(a,e,"ready",function(){i.removeChild(a);g()});a.src=c;i.insertBefore(a,i.firstChild)}}else if(F){a.async=false;t(a,e,"finished",g);a.src=c;i.insertBefore(a,i.firstChild)}else{t(a,e,"finished",g);a.src=c;i.insertBefore(a,i.firstChild)}},0)}function J(){var l={},Q=r||M,n=[],p={},m;l[y]=true;l[z]=false;l[u]=false;l[A]=false;l[B]="";function R(a,c,b){var d;function f(){if(d!=null){d=null;I(b)}}if(p[c.src].finished)return;if(!a[u])p[c.src].finished=true;d=b.elem||document.createElement("script");if(c.type)d.type=c.type;if(c.charset)d.charset=c.charset;t(d,b,"finished",f);if(b.elem){b.elem=null}else if(b.text){d.onload=d.onreadystatechange=null;d.text=b.text}else{d.src=c.real_src}i.insertBefore(d,i.firstChild);if(b.text){f()}}function S(c,b,d,f){var e,g,h=function(){b.ready_cb(b,function(){R(c,b,e)})},j=function(){b.finished_cb(b,d)};b.src=N(b.src,c[B]);b.real_src=b.src+(c[A]?((/\?.*$/.test(b.src)?"&_":"?_")+~~(Math.random()*1E9)+"="):"");if(!p[b.src])p[b.src]={items:[],finished:false};g=p[b.src].items;if(c[u]||g.length==0){e=g[g.length]={ready:false,finished:false,ready_listeners:[h],finished_listeners:[j]};P(c,b,e,((f)?function(){e.ready=true;for(var a=0;a<e.ready_listeners.length;a++){e.ready_listeners[a]()}e.ready_listeners=[]}:function(){I(e)}),f)}else{e=g[0];if(e.finished){j()}else{e.finished_listeners.push(j)}}}function v(){var e,g=s(l,{}),h=[],j=0,w=false,k;function T(a,c){a.ready=true;a.exec_trigger=c;x()}function U(a,c){a.ready=a.finished=true;a.exec_trigger=null;for(var b=0;b<c.scripts.length;b++){if(!c.scripts[b].finished)return}c.finished=true;x()}function x(){while(j<h.length){if(G(h[j])){try{h[j++]()}catch(err){}continue}else if(!h[j].finished){if(O(h[j]))continue;break}j++}if(j==h.length){w=false;k=false}}function V(){if(!k||!k.scripts){h.push(k={scripts:[],finished:true})}}e={script:function(){for(var f=0;f<arguments.length;f++){(function(a,c){var b;if(!H(a)){c=[a]}for(var d=0;d<c.length;d++){V();a=c[d];if(G(a))a=a();if(!a)continue;if(H(a)){b=[].slice.call(a);b.unshift(d,1);[].splice.apply(c,b);d--;continue}if(typeof a=="string")a={src:a};a=s(a,{ready:false,ready_cb:T,finished:false,finished_cb:U});k.finished=false;k.scripts.push(a);S(g,a,k,(Q&&w));w=true;if(g[z])e.wait()}})(arguments[f],arguments[f])}return e},wait:function(){if(arguments.length>0){for(var a=0;a<arguments.length;a++){h.push(arguments[a])}k=h[h.length-1]}else k=false;x();return e}};return{script:e.script,wait:e.wait,setOptions:function(a){s(a,g);return e}}}m={setGlobalDefaults:function(a){s(a,l);return m},setOptions:function(){return v().setOptions.apply(null,arguments)},script:function(){return v().script.apply(null,arguments)},wait:function(){return v().wait.apply(null,arguments)},queueScript:function(){n[n.length]={type:"script",args:[].slice.call(arguments)};return m},queueWait:function(){n[n.length]={type:"wait",args:[].slice.call(arguments)};return m},runQueue:function(){var a=m,c=n.length,b=c,d;for(;--b>=0;){d=n.shift();a=a[d.type].apply(null,d.args)}return a},noConflict:function(){o.$LAB=K;return m},sandbox:function(){return J()}};return m}o.$LAB=J();(function(a,c,b){if(document.readyState==null&&document[a]){document.readyState="loading";document[a](c,b=function(){document.removeEventListener(c,b,false);document.readyState="complete"},false)}})("addEventListener","DOMContentLoaded")})(this);/* init.js - initialization and configuration of Popcorn and the widgets
+(function(o){var K=o.$LAB,y="UseLocalXHR",z="AlwaysPreserveOrder",u="AllowDuplicates",A="CacheBust",B="BasePath",C=/^[^?#]*\//.exec(location.href)[0],D=/^\w+\:\/\/\/?[^\/]+/.exec(C)[0],i=document.head||document.getElementsByTagName("head"),L=(o.opera&&Object.prototype.toString.call(o.opera)=="[object Opera]")||("MozAppearance"in document.documentElement.style),q=document.createElement("script"),E=typeof q.preload=="boolean",r=E||(q.readyState&&q.readyState=="uninitialized"),F=!r&&q.async===true,M=!r&&!F&&!L;function G(a){return Object.prototype.toString.call(a)=="[object Function]"}function H(a){return Object.prototype.toString.call(a)=="[object Array]"}function N(a,c){var b=/^\w+\:\/\//;if(/^\/\/\/?/.test(a)){a=location.protocol+a}else if(!b.test(a)&&a.charAt(0)!="/"){a=(c||"")+a}return b.test(a)?a:((a.charAt(0)=="/"?D:C)+a)}function s(a,c){for(var b in a){if(a.hasOwnProperty(b)){c[b]=a[b]}}return c}function O(a){var c=false;for(var b=0;b<a.scripts.length;b++){if(a.scripts[b].ready&&a.scripts[b].exec_trigger){c=true;a.scripts[b].exec_trigger();a.scripts[b].exec_trigger=null}}return c}function t(a,c,b,d){a.onload=a.onreadystatechange=function(){if((a.readyState&&a.readyState!="complete"&&a.readyState!="loaded")||c[b])return;a.onload=a.onreadystatechange=null;d()}}function I(a){a.ready=a.finished=true;for(var c=0;c<a.finished_listeners.length;c++){a.finished_listeners[c]()}a.ready_listeners=[];a.finished_listeners=[]}function P(d,f,e,g,h){setTimeout(function(){var a,c=f.real_src,b;if("item"in i){if(!i[0]){setTimeout(arguments.callee,25);return}i=i[0]}a=document.createElement("script");if(f.type)a.type=f.type;if(f.charset)a.charset=f.charset;if(h){if(r){e.elem=a;if(E){a.preload=true;a.onpreload=g}else{a.onreadystatechange=function(){if(a.readyState=="loaded")g()}}a.src=c}else if(h&&c.indexOf(D)==0&&d[y]){b=new XMLHttpRequest();b.onreadystatechange=function(){if(b.readyState==4){b.onreadystatechange=function(){};e.text=b.responseText+"\n//@ sourceURL="+c;g()}};b.open("GET",c);b.send()}else{a.type="text/cache-script";t(a,e,"ready",function(){i.removeChild(a);g()});a.src=c;i.insertBefore(a,i.firstChild)}}else if(F){a.async=false;t(a,e,"finished",g);a.src=c;i.insertBefore(a,i.firstChild)}else{t(a,e,"finished",g);a.src=c;i.insertBefore(a,i.firstChild)}},0)}function J(){var l={},Q=r||M,n=[],p={},m;l[y]=true;l[z]=false;l[u]=false;l[A]=false;l[B]="";function R(a,c,b){var d;function f(){if(d!=null){d=null;I(b)}}if(p[c.src].finished)return;if(!a[u])p[c.src].finished=true;d=b.elem||document.createElement("script");if(c.type)d.type=c.type;if(c.charset)d.charset=c.charset;t(d,b,"finished",f);if(b.elem){b.elem=null}else if(b.text){d.onload=d.onreadystatechange=null;d.text=b.text}else{d.src=c.real_src}i.insertBefore(d,i.firstChild);if(b.text){f()}}function S(c,b,d,f){var e,g,h=function(){b.ready_cb(b,function(){R(c,b,e)})},j=function(){b.finished_cb(b,d)};b.src=N(b.src,c[B]);b.real_src=b.src+(c[A]?((/\?.*$/.test(b.src)?"&_":"?_")+~~(Math.random()*1E9)+"="):"");if(!p[b.src])p[b.src]={items:[],finished:false};g=p[b.src].items;if(c[u]||g.length==0){e=g[g.length]={ready:false,finished:false,ready_listeners:[h],finished_listeners:[j]};P(c,b,e,((f)?function(){e.ready=true;for(var a=0;a<e.ready_listeners.length;a++){e.ready_listeners[a]()}e.ready_listeners=[]}:function(){I(e)}),f)}else{e=g[0];if(e.finished){j()}else{e.finished_listeners.push(j)}}}function v(){var e,g=s(l,{}),h=[],j=0,w=false,k;function T(a,c){a.ready=true;a.exec_trigger=c;x()}function U(a,c){a.ready=a.finished=true;a.exec_trigger=null;for(var b=0;b<c.scripts.length;b++){if(!c.scripts[b].finished)return}c.finished=true;x()}function x(){while(j<h.length){if(G(h[j])){try{h[j++]()}catch(err){}continue}else if(!h[j].finished){if(O(h[j]))continue;break}j++}if(j==h.length){w=false;k=false}}function V(){if(!k||!k.scripts){h.push(k={scripts:[],finished:true})}}e={script:function(){for(var f=0;f<arguments.length;f++){(function(a,c){var b;if(!H(a)){c=[a]}for(var d=0;d<c.length;d++){V();a=c[d];if(G(a))a=a();if(!a)continue;if(H(a)){b=[].slice.call(a);b.unshift(d,1);[].splice.apply(c,b);d--;continue}if(typeof a=="string")a={src:a};a=s(a,{ready:false,ready_cb:T,finished:false,finished_cb:U});k.finished=false;k.scripts.push(a);S(g,a,k,(Q&&w));w=true;if(g[z])e.wait()}})(arguments[f],arguments[f])}return e},wait:function(){if(arguments.length>0){for(var a=0;a<arguments.length;a++){h.push(arguments[a])}k=h[h.length-1]}else k=false;x();return e}};return{script:e.script,wait:e.wait,setOptions:function(a){s(a,g);return e}}}m={setGlobalDefaults:function(a){s(a,l);return m},setOptions:function(){return v().setOptions.apply(null,arguments)},script:function(){return v().script.apply(null,arguments)},wait:function(){return v().wait.apply(null,arguments)},queueScript:function(){n[n.length]={type:"script",args:[].slice.call(arguments)};return m},queueWait:function(){n[n.length]={type:"wait",args:[].slice.call(arguments)};return m},runQueue:function(){var a=m,c=n.length,b=c,d;for(;--b>=0;){d=n.shift();a=a[d.type].apply(null,d.args)}return a},noConflict:function(){o.$LAB=K;return m},sandbox:function(){return J()}};return m}o.$LAB=J();(function(a,c,b){if(document.readyState==null&&document[a]){document.readyState="loading";document[a](c,b=function(){document.removeEventListener(c,b,false);document.readyState="complete"},false)}})("addEventListener","DOMContentLoaded")})(this);/* init.js - initialization and configuration of the widgets
 */
 
 if (typeof window.IriSP === "undefined") {
-    IriSP = {};
+    window.IriSP = {};
 }
 
 /* The Metadataplayer Object, single point of entry, replaces IriSP.init_player */
@@ -32,43 +32,34 @@
 IriSP.Metadataplayer = function(config) {
     IriSP.log("IriSP.Metadataplayer constructor");
     for (var key in IriSP.guiDefaults) {
-        if (IriSP.guiDefaults.hasOwnProperty(key) && !config.gui.hasOwnProperty(key)) {
-            config.gui[key] = IriSP.guiDefaults[key]
+        if (IriSP.guiDefaults.hasOwnProperty(key) && !config.hasOwnProperty(key)) {
+            config[key] = IriSP.guiDefaults[key]
         }
     }
-    var _container = document.getElementById(config.gui.container);
+    var _container = document.getElementById(config.container);
     _container.innerHTML = '<h3 class="Ldt-Loader">Loading... Chargement...</h3>';
     this.sourceManager = new IriSP.Model.Directory();
     this.config = config;
-    this.callbackQueue = [];
-    this.isLoaded = false;
+    this.__events = {};
     this.loadLibs();
 }
 
 IriSP.Metadataplayer.prototype.toString = function() {
-    return 'Metadataplayer in #' + this.config.gui.container;
-}
-
-IriSP.Metadataplayer.prototype.deferCallback = function(_callback) {
-    var _this = this;
-    IriSP._.defer(function() {
-        _callback.call(_this);
-    });
+    return 'Metadataplayer in #' + this.config.container;
 }
 
-IriSP.Metadataplayer.prototype.handleCallbacks = function() {
-    this.isLoaded = true;
-    while (this.callbackQueue.length) {
-        this.deferCallback(this.callbackQueue.splice(0,1)[0]);
+IriSP.Metadataplayer.prototype.on = function(_event, _callback) {
+    if (typeof this.__events[_event] === "undefined") {
+        this.__events[_event] = [];
     }
+    this.__events[_event].push(_callback);
 }
 
-IriSP.Metadataplayer.prototype.onLoad = function(_callback) {
-    if (this.isLoaded) {
-        this.deferCallback(_callback);
-    } else {
-        this.callbackQueue.push(_callback);
-    }
+IriSP.Metadataplayer.prototype.trigger = function(_event, _data) {
+    var _element = this;
+    IriSP._(this.__events[_event]).each(function(_callback) {
+        _callback.call(_element, _data);
+    });
 }
 
 IriSP.Metadataplayer.prototype.loadLibs = function() {
@@ -76,8 +67,7 @@
     var $L = $LAB
         .script(IriSP.getLib("underscore"))
         .script(IriSP.getLib("Mustache"))
-        .script(IriSP.getLib("jQuery"))
-        .script(IriSP.getLib("swfObject"));
+        .script(IriSP.getLib("jQuery"));
     
     if (typeof JSON == "undefined") {
         $L.script(IriSP.getLib("json"));
@@ -86,24 +76,18 @@
     $L.wait()
         .script(IriSP.getLib("jQueryUI"));
 
-    if (this.config.player.type === "jwplayer" || this.config.player.type === "auto") {
-        $L.script(IriSP.getLib("jwplayer"));
-    }
-    
-    if (this.config.player.type !== "jwplayer" && this.config.player.type !== "allocine" && this.config.player.type !== "dailymotion") {
-        $L.script(IriSP.getLib("popcorn"));
-    }
-
     /* widget specific requirements */
-    for(var _i = 0; _i < this.config.gui.widgets.length; _i++) {
-        var _t = this.config.gui.widgets[_i].type;
-        if (typeof IriSP.widgetsRequirements[_t] !== "undefined" && typeof IriSP.widgetsRequirements[_t].requires !== "undefined") {
-            $L.script(IriSP.getLib(IriSP.widgetsRequirements[_t].requires));
+    for(var _i = 0; _i < this.config.widgets.length; _i++) {
+        var _t = this.config.widgets[_i].type;
+        if (typeof IriSP.widgetsRequirements[_t] !== "undefined" && typeof IriSP.widgetsRequirements[_t].requires !== "undefined" ) {
+            for (var _j = 0; _j < IriSP.widgetsRequirements[_t].requires.length; _j++) {
+                $L.script(IriSP.getLib(IriSP.widgetsRequirements[_t].requires[_j]));
+            }
         }
     }
     
     var _this = this;
-    IriSP.log($L);
+    
     $L.wait(function() {
         _this.onLibsLoaded();
     });
@@ -115,25 +99,28 @@
         IriSP.jQuery = window.jQuery.noConflict();
     }
     if (typeof IriSP._ === "undefined" && typeof window._ !== "undefined") {
-        IriSP._ = window._.noConflict();
+        IriSP._ = window._;
     }
     IriSP.loadCss(IriSP.getLib("cssjQueryUI"));
-    IriSP.loadCss(this.config.gui.css);
+    IriSP.loadCss(this.config.css);
     
-    this.videoData = this.loadMetadata(this.config.player.metadata);
-    this.$ = IriSP.jQuery('#' + this.config.gui.container);
+    this.$ = IriSP.jQuery('#' + this.config.container);
     this.$.css({
-        "width": this.config.gui.width,
+        "width": this.config.width,
         "clear": "both"
     });
-    if (typeof this.config.gui.height !== "undefined") {
-        this.$.css("height", this.config.gui.height);
+    if (typeof this.config.height !== "undefined") {
+        this.$.css("height", this.config.height);
     }
       
+    this.widgets = [];
     var _this = this;
-    this.videoData.onLoad(function() {
-        _this.onVideoDataLoaded();
-    });
+    for(var i = 0; i < this.config.widgets.length; i++) {
+        this.loadWidget(this.config.widgets[i], function(_widget) {
+            _this.widgets.push(_widget)
+        });
+    };
+    this.$.find('.Ldt-Loader').detach();
 }
 
 IriSP.Metadataplayer.prototype.loadMetadata = function(_metadataInfo) {
@@ -150,184 +137,6 @@
     }
 }
 
-IriSP.Metadataplayer.prototype.onVideoDataLoaded = function() {
-    
-    /* Setting default media from metadata */
-   
-    if (typeof this.videoData !== "undefined") {
-        
-        var _media;
-        
-        if (typeof this.videoData.mainMedia !== "undefined") {
-            _media = this.videoData.getElement(this.videoData.mainMedia);
-        }
-        
-        if (this.config.player.type === "mashup" || this.config.player.type === "mashup-html") {
-            if (typeof _media === "undefined" || _media.elementType !== "mashup") {
-                var _mashups = this.videoData.getMashups();
-                if (_mashups.length) {
-                    _media = _mashups[0];
-                }
-            }
-        } else {
-            if (typeof _media === "undefined" || _media.elementType !== "media") {
-                var _medias = this.videoData.getMedias();
-                if (_medias.length) {
-                    _media = _medias[0];
-                }
-            }
-        }
-        
-        this.videoData.currentMedia = _media;
-        
-        /* Getting video URL from metadata if it's not in the player config options */
-        
-        if (typeof _media !== "undefined" && typeof _media.video !== "undefined" && typeof this.config.player.video === "undefined") {
-            this.config.player.video = _media.video;
-            if (typeof this.config.player.streamer == "undefined" && typeof _media.streamer !== "undefined") {
-                this.config.player.streamer = _media.streamer;
-            }
-        }
-        
-    }
-    
-    if (typeof this.config.player.video === "string" && this.config.player.url_transform === "function") {
-        this.config.player.video = this.config.player.url_transform(this.config.player.video);
-    }
-    
-    var _pop,
-        _divs = this.layoutDivs("video",this.config.player.height || undefined),
-        containerDiv = _divs[0],
-        spacerDiv = _divs[1],
-        _this = this,
-        _types = {
-            "html5" : /\.(ogg|ogv|webm)$/,
-            "youtube" : /^(https?:\/\/)?(www\.)?youtube\.com/,
-            "dailymotion" : /^(https?:\/\/)?(www\.)?dailymotion\.com/
-        };
-    
-    if (this.config.player.type === "auto") {
-        this.config.player.type = "jwplayer";
-        IriSP._(_types).each(function(_v, _k) {
-            if (_v.test(_this.config.player.video)) {
-                _this.config.player.type = _k
-            }
-        });
-    }
-
-    switch(this.config.player.type) {
-        case "html5":
-            var _tmpId = Popcorn.guid("video"),
-                _videoEl = IriSP.jQuery('<video>');
-            
-            _videoEl.attr({
-                "src" : this.config.player.video,
-                "id" : _tmpId
-            })
-
-            if(this.config.player.hasOwnProperty("width")) {
-                _videoEl.attr("width", this.config.player.width);
-            }
-            if(this.config.player.hasOwnProperty("height")) {
-                _videoEl.attr("height", this.config.player.height);
-            }
-            IriSP.jQuery("#" + containerDiv).append(_videoEl);
-            _pop = Popcorn("#" + _tmpId);
-            break;
-
-        case "html5-audio":
-            var _tmpId = Popcorn.guid("audio"),
-                _videoEl = IriSP.jQuery('<audio>');
-            
-            _videoEl.attr({
-                "src" : this.config.player.video,
-                "id" : _tmpId
-            })
-
-            if(this.config.player.hasOwnProperty("width")) {
-                _videoEl.attr("width", this.config.player.width);
-            }
-            if(this.config.player.hasOwnProperty("height")) {
-                _videoEl.attr("height", this.config.player.height);
-            }
-            IriSP.jQuery("#" + containerDiv).append(_videoEl);
-            _pop = Popcorn("#" + _tmpId);
-            break;
-
-        case "jwplayer":
-            var opts = IriSP.jQuery.extend({}, this.config.player);
-            delete opts.container;
-            delete opts.type;
-            if (typeof opts.streamer !== "undefined") {
-                opts.video = opts.video.replace(opts.streamer,"");
-            }
-            opts.file = opts.video;
-            delete opts.video;
-            delete opts.metadata;
-
-            if(!opts.hasOwnProperty("flashplayer")) {
-                opts.flashplayer = IriSP.getLib("jwPlayerSWF");
-            }
-
-            if(!opts.hasOwnProperty("controlbar.position")) {
-                opts["controlbar.position"] = "none";
-            }
-            _pop = new IriSP.PopcornReplacement.jwplayer("#" + containerDiv, opts);
-            break;
-
-        case "youtube":
-            // Popcorn.youtube wants us to specify the size of the player in the style attribute of its container div.
-            IriSP.jQuery("#" + containerDiv).css({
-                width : this.config.player.width + "px",
-                height : this.config.player.height + "px"
-            });
-            var _urlparts = this.config.player.video.split(/[?&]/),
-                _params = {};
-            for (var _j = 1; _j < _urlparts.length; _j++) {
-                var _ppart = _urlparts[_j].split('=');
-                _params[_ppart[0]] = decodeURIComponent(_ppart[1]);
-            }
-            _params.controls = 0;
-            _params.modestbranding = 1;
-            _url = _urlparts[0] + '?' + IriSP.jQuery.param(_params);
-            _pop = Popcorn.youtube("#" + containerDiv, _url);
-            break;
-
-        case "dailymotion":
-            _pop = new IriSP.PopcornReplacement.dailymotion("#" + containerDiv, this.config.player);
-            break;
-
-        case "mashup":
-            _pop = new IriSP.PopcornReplacement.mashup("#" + containerDiv, this.config.player);
-            break;
-            
-        case "allocine":
-            _pop = new IriSP.PopcornReplacement.allocine("#" + containerDiv, this.config.player);
-            break;
-        
-        case "mashup-html":
-            _pop = new IriSP.PopcornReplacement.htmlMashup("#" + containerDiv, this.config.player, this.videoData);
-            break;
-        
-        default:
-            _pop = undefined;
-    };
-
-    this.popcorn = _pop;
-    
-    /* Now Loading Widgets */
-    
-    this.widgets = [];
-    var _this = this;
-    for(var i = 0; i < this.config.gui.widgets.length; i++) {
-        this.loadWidget(this.config.gui.widgets[i], function(_widget) {
-            _this.widgets.push(_widget)
-        });
-    };
-    this.$.find('.Ldt-Loader').detach();
-    this.handleCallbacks();
-}
-
 IriSP.Metadataplayer.prototype.loadWidget = function(_widgetConfig, _callback) {
     /* Creating containers if needed */
     if (typeof _widgetConfig.container === "undefined") {
@@ -361,20 +170,20 @@
     if (typeof(_name) === "undefined") {
        _name = "";
     }
-    var newDiv = IriSP._.uniqueId(this.config.gui.container + "_widget_" + _name + "_"),
+    var newDiv = IriSP._.uniqueId(this.config.container + "_widget_" + _name + "_"),
         spacerDiv = IriSP._.uniqueId("LdtPlayer_spacer_"),
         divHtml = IriSP.jQuery('<div>')
             .attr("id",newDiv)
             .css({
-                width: this.config.gui.width + "px",
+                width: this.config.width + "px",
                 position: "relative",
                 clear: "both"
             }),
         spacerHtml = IriSP.jQuery('<div>')
             .attr("id",spacerDiv)
             .css({
-                width: this.config.gui.width + "px",
-                height: this.config.gui.spacer_div_height + "px",
+                width: this.config.width + "px",
+                height: this.config.spacer_div_height + "px",
                 position: "relative",
                 clear: "both"
             });
@@ -423,154 +232,7 @@
         console.log.apply(console, arguments);
     }
 }
-/* wrapper that simulates popcorn.js because
-   popcorn is a bit unstable at the time */
-
-/* Popcorn.code replacement has been disabled. It didn't work properly and was not even used  */
-
-IriSP.PopcornReplacement = {  
-};
-
-/** base class for our popcorn-compatible players.
- */
-IriSP.PopcornReplacement.player = function(container, options) {
-  
-    this.media = { 
-        "paused": true,
-        "muted": false
-    };
-    
-    this.container = container.replace(/^#/,''); //remove '#' at beginning
-    this.msgPump = {}; /* dictionnary used to receive and send messages */
-    this._options = options;
-
-};
-
-IriSP.PopcornReplacement.player.prototype.listen = function(msg, callback) {
-    if (!this.msgPump.hasOwnProperty(msg)) {
-        this.msgPump[msg] = [];
-    }
-    this.msgPump[msg].push(callback);
-};
-
-IriSP.PopcornReplacement.player.prototype.on = IriSP.PopcornReplacement.player.prototype.listen;
-
-IriSP.PopcornReplacement.player.prototype.trigger = function(msg, params) {
-    if (!this.msgPump.hasOwnProperty(msg)) {
-        return;
-    }
-    var d = this.msgPump[msg];
-    for(var i = 0; i < d.length; i++) {
-        d[i].call(window, params);
-    }
-};
-
-IriSP.PopcornReplacement.player.prototype.emit = IriSP.PopcornReplacement.player.prototype.trigger;
-/*
-IriSP.PopcornReplacement.player.prototype.guid = function(prefix) {
-  var str = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
-      var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
-      return v.toString(16);
-   });
-
-  return prefix + str;
-};
-
-/** init the api after that flash player has been setup - called by the callback
-    defined by the embedded flash player 
-
-IriSP.PopcornReplacement.player.prototype.__initApi = function() {
-  this.trigger("loadedmetadata"); // we've done more than loading metadata of course,
-                                                      // but popcorn doesn't need to know more.
-  this.media.muted = this.playerFns.getMute();
-  /* some programmed segments are supposed to be run at the beginning 
-  var i = 0;
-  for(i = 0; i < this.__codes.length; i++) {
-    var c = this.__codes[i];
-    if (0 == c.start) {
-      c.onStart();
-    }
-    
-    if (0 == c.end) {
-      c.onEnd();
-    }
-  }
-  
-};
-*/
-
-IriSP.PopcornReplacement.player.prototype.currentTime = function(time) {
-  if (typeof(time) === "undefined") {        
-      return this.playerFns.getPosition();            
-  } else {
-     var currentTime = +time;
-     this.playerFns.seek(currentTime);              
-     return currentTime;
-  }
-};
-
-IriSP.PopcornReplacement.player.prototype.play = function() {
-  this.media.paused = false;
-  this.trigger("play");
-  this.playerFns.play();
-};
-    
-IriSP.PopcornReplacement.player.prototype.pause = function() {
-    this.media.paused = true;
-    this.trigger("pause");
-    this.playerFns.pause();
-};
-
-IriSP.PopcornReplacement.player.prototype.muted = function(val) {
-  if (typeof(val) !== "undefined") {
-
-    if (this.playerFns.getMute() !== val) {
-      if (val) {
-        this.playerFns.setMute(true);
-        this.media.muted = true;
-      } else {
-        this.playerFns.setMute(false);
-        this.media.muted = false;
-      }
-
-      this.trigger( "volumechange" );
-    }
-    
-    return this.playerFns.getMute();
-  } else {
-    return this.playerFns.getMute();
-  }
-};
-
-IriSP.PopcornReplacement.player.prototype.volume = function(val) {
-    if (typeof this.playerFns.getVolume == "undefined" || typeof this.playerFns.setVolume == "undefined") {
-        return false;
-    }
-    var _vol = this.playerFns.getVolume();
-    if (typeof(val) !== "undefined" && parseFloat(val) !== NaN) {
-        val = Math.max(0, Math.min(1, val));
-        if (parseFloat(val) != parseFloat(_vol)) {
-            this.playerFns.setVolume(val);
-            this.trigger("volumechange");
-            _vol = this.playerFns.getVolume();
-        }
-    }
-    return _vol;
-};
-
-IriSP.PopcornReplacement.player.prototype.mute = function() {
-    this.muted(true);
-}
-
-IriSP.PopcornReplacement.player.prototype.unmute = function() {
-    this.muted(false);
-}
-
-
-IriSP.PopcornReplacement.player.prototype.roundTime = function() {
-  var currentTime = this.currentTime();
-  return Math.round(currentTime);
-};/* TODO: Separate Project-specific data from Source */
+/* TODO: Separate Project-specific data from Source */
 
 /* model.js is where data is stored in a standard form, whatever the serializer */
 
@@ -658,6 +320,7 @@
     Array.call(this);
     this.directory = _directory;
     this.idIndex = [];
+    this.__events = {};
     if (typeof _directory == "undefined") {
         console.trace();
         throw "Error : new IriSP.Model.List(directory): directory is undefined";
@@ -666,12 +329,8 @@
 
 IriSP.Model.List.prototype = new Array();
 
-IriSP.Model.List.prototype.getElement = function(_id) {
-    return this[_id];
-}
-
 IriSP.Model.List.prototype.hasId = function(_id) {
-    return (IriSP._(this.idIndex).indexOf(_id) !== -1);
+    return IriSP._(this.idIndex).include(_id);
 }
 
 /* On recent browsers, forEach and map are defined and do what we want.
@@ -835,6 +494,20 @@
     });
 }
 
+IriSP.Model.List.prototype.on = function(_event, _callback) {
+    if (typeof this.__events[_event] === "undefined") {
+        this.__events[_event] = [];
+    }
+    this.__events[_event].push(_callback);
+}
+
+IriSP.Model.List.prototype.trigger = function(_event, _data) {
+    var _list = this;
+    IriSP._(this.__events[_event]).each(function(_callback) {
+        _callback.call(_list, _data);
+    });
+}
+
 /* A simple time management object, that helps converting millisecs to seconds and strings,
  * without the clumsiness of the original Date object.
  */
@@ -925,7 +598,7 @@
         this.contents = new IriSP.Model.List(this.source.directory);
         this.contents.addIds(this.id);
     } else {
-        this.contents = this.source.directory.getElement(this.id);
+        this.contents = this.source.getElement(this.id);
     }
     
 }
@@ -959,6 +632,7 @@
     this.id = _id;
     this.title = "";
     this.description = "";
+    this.__events = {}
     this.source.directory.addElement(this);
 }
 
@@ -985,6 +659,20 @@
     });
 }
 
+IriSP.Model.Element.prototype.on = function(_event, _callback) {
+    if (typeof this.__events[_event] === "undefined") {
+        this.__events[_event] = [];
+    }
+    this.__events[_event].push(_callback);
+}
+
+IriSP.Model.Element.prototype.trigger = function(_event, _data) {
+    var _element = this;
+    IriSP._(this.__events[_event]).each(function(_callback) {
+        _callback.call(_element, _data);
+    });
+}
+
 /* */
 
 IriSP.Model.Media = function(_id, _source) {
@@ -992,10 +680,42 @@
     this.elementType = 'media';
     this.duration = new IriSP.Model.Time();
     this.video = '';
+    var _this = this;
+    this.on("timeupdate", function(_time) {
+        _this.getAnnotations().filter(function(_a) {
+            return (_a.end <= _time || _a.begin > _time) && _a.playing
+        }).forEach(function(_a) {
+            _a.playing = false;
+            _a.trigger("leave");
+        });
+        _this.getAnnotations().filter(function(_a) {
+            return _a.begin <= _time && _a.end > _time && !_a.playing
+        }).forEach(function(_a) {
+            _a.playing = true;
+            _a.trigger("enter");
+        });
+    });
 }
 
 IriSP.Model.Media.prototype = new IriSP.Model.Element();
 
+/* Default functions to be overriden by players */
+
+IriSP.Model.Media.prototype.getCurrentTime = function() {  return new IriSP.Model.Time(0); }
+
+IriSP.Model.Media.prototype.getVolume = function() { return .5; }
+
+IriSP.Model.Media.prototype.getPaused = function() { return true; }
+
+IriSP.Model.Media.prototype.getMuted = function() { return false; }
+
+IriSP.Model.Media.prototype.setCurrentTime
+    = IriSP.Model.Media.prototype.setVolume
+    = IriSP.Model.Media.prototype.setMuted
+    = IriSP.Model.Media.prototype.play
+    = IriSP.Model.Media.prototype.pause
+    = function() {}
+    
 IriSP.Model.Media.prototype.setDuration = function(_durationMs) {
     this.duration.setMilliseconds(_durationMs);
 }
@@ -1049,6 +769,11 @@
     this.elementType = 'annotation';
     this.begin = new IriSP.Model.Time();
     this.end = new IriSP.Model.Time();
+    this.playing = false;
+    var _this = this;
+    this.on("click", function() {
+        _this.getMedia().setCurrentTime(_this.begin);
+    });
 }
 
 IriSP.Model.Annotation.prototype = new IriSP.Model.Element(null);
@@ -1104,6 +829,10 @@
     this.title = this.annotation.title;
     this.description = this.annotation.description;
     this.color = this.annotation.color;
+    var _this = this;
+    this.on("click", function() {
+        _mashup.setCurrentTime(_this.begin);
+    });
 }
 
 IriSP.Model.MashedAnnotation.prototype = new IriSP.Model.Element(null);
@@ -1124,6 +853,10 @@
     return this.annotation.getTags().getTitles();
 }
 
+IriSP.Model.MashedAnnotation.prototype.getDuration = function() {
+    return this.annotation.getDuration();
+}
+
 /* */
 
 IriSP.Model.Mashup = function(_id, _source) {
@@ -1132,6 +865,30 @@
     this.duration = new IriSP.Model.Time();
     this.segments = new IriSP.Model.List(_source.directory);
     this.medias = new IriSP.Model.List(_source.directory);
+    var _currentMedia = null;
+    var _this = this;
+    this.on("timeupdate", function(_time) {
+        _this.getAnnotations().filter(function(_a) {
+            return (_a.end <= _time || _a.begin > _time) && _a.playing
+        }).forEach(function(_a) {
+            _a.playing = false;
+            _a.trigger("leave");
+        });
+        _this.getAnnotations().filter(function(_a) {
+            return _a.begin <= _time && _a.end > _time && !_a.playing
+        }).forEach(function(_a) {
+            _a.playing = true;
+            _a.trigger("enter");
+            var _m = _a.getMedia();
+            if (_m !== _currentMedia) {
+                if (_currentMedia) {
+                    _currentMedia.trigger("leave");
+                }
+                _m.trigger("enter");
+                _currentMedia = _m;
+            }
+        });
+    });
 }
 
 IriSP.Model.Mashup.prototype = new IriSP.Model.Element();
@@ -1189,6 +946,23 @@
     }
 }
 
+/* Default functions to be overriden by players */
+
+IriSP.Model.Mashup.prototype.getCurrentTime = function() { return new IriSP.Model.Time(0); }
+
+IriSP.Model.Mashup.prototype.getVolume = function() { return .5; }
+
+IriSP.Model.Mashup.prototype.getPaused = function() { return true; }
+
+IriSP.Model.Mashup.prototype.getMuted = function() { return false; }
+
+IriSP.Model.Mashup.prototype.setCurrentTime
+    = IriSP.Model.Mashup.prototype.setVolume
+    = IriSP.Model.Mashup.prototype.setMuted
+    = IriSP.Model.Mashup.prototype.play
+    = IriSP.Model.Mashup.prototype.pause
+    = function() {}
+
 /* */
 
 IriSP.Model.Source = function(_config) {
@@ -1310,6 +1084,23 @@
     }
 }
 
+IriSP.Model.Source.prototype.getCurrentMedia = function(_opts) {
+    if (typeof this.currentMedia === "undefined") {
+        if (_opts.is_mashup) {
+            var _mashups = this.getMashups();
+            if (_mashups.length) {
+                this.currentMedia = _mashups[0];
+            }
+        } else {
+            var _medias = this.getMedias();
+            if (_medias.length) {
+                _media = _medias[0];
+            }
+        }
+    }
+    return this.currentMedia;
+}
+
 IriSP.Model.Source.prototype.merge = function(_source) {
     var _this = this;
     _source.forEach(function(_value, _key) {
@@ -1389,15 +1180,29 @@
         raphael : "raphael-min.js",
         tracemanager : "tracemanager.js",
         jwPlayerSWF : "player.swf",
-        json : "json2.js"
+        json : "json2.js",
+        zeroClipboardJs: "ZeroClipboard.js",
+        zeroClipboardSwf: "ZeroClipboard.swf",
+        backbone: "backbone.js",
+        backboneRelational: "backbone-relational.js",
+        paper: "paper.js",
+        jqueryMousewheel: "jquery.mousewheel.min.js",
+        renkanPublish: "renkan-publish.js",
+        processing: "processing-1.3.6.min.js",
+        recordMicSwf: "record_mic.swf"
     },
     locations : {
-        // use to define locations outside defautl_dir
+        // use to define locations outside default_dir
     },
     cdn : {
-        jQueryUI : "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.17/jquery-ui.js",
+        jQuery : "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2.min.js",
+        jQueryUI : "http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.22/jquery-ui.min.js",
         swfObject : "http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js",
-        cssjQueryUI : "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/themes/base/jquery-ui.css"
+        cssjQueryUI : "http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.22/themes/ui-lightness/jquery-ui.css",
+        underscore : "http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.3.3/underscore-min.js",
+        Mustache : "http://cdnjs.cloudflare.com/ajax/libs/mustache.js/0.5.0-dev/mustache.min.js",
+        raphael : "http://cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js",
+        json : "http://cdnjs.cloudflare.com/ajax/libs/json2/20110223/json2.js"
     },
     useCdn : false
 }
@@ -1405,20 +1210,53 @@
 IriSP.widgetsDir = 'widgets';
 
 IriSP.widgetsRequirements = {
+    PopcornPlayer: {
+        noCss: true,
+        requires: [ "popcorn" ]
+    },
+    JwpPlayer: {
+        noCss: true,
+        requires: [ "jwplayer" ]
+    },
+    DailymotionPlayer: {
+        noCss: true,
+        requires: [ "swfObject" ]
+    },
+    AutoPlayer: {
+        noCss: true
+    },
+    MashupPlayer: {
+        noCss: true
+    },
+    AnnotationsList: {
+        requires: [ "jwplayer" ]
+    },
     Sparkline: {
         noCss: true,
-        requires: "raphael"
+        requires: [ "raphael" ]
     },
     Arrow: {
         noCss: true,
-        requires: "raphael"
+        requires: [ "raphael" ]
     },
     Mediafragment: {
         noCss: true
     },
     Trace : {
         noCss: true,
-        requires: "tracemanager"
+        requires: [ "tracemanager" ]
+    },
+    Slideshare: {
+        requires: [ "swfObject" ]
+    },
+    Social: {
+        requires: [ "zeroClipboardJs" ]
+    },
+    Renkan: {
+        requires: [ "backbone", "backboneRelational", "paper", "jqueryMousewheel", "renkanPublish" ]
+    },
+    KnowledgeConcierge: {
+        requires: [ "processing" ]
     }
 }
 
@@ -1455,7 +1293,7 @@
     
     /* Setting all the configuration options */
     var _type = config.type,
-        _config = IriSP._.defaults({}, config, player.config.gui.default_options, this.defaults),
+        _config = IriSP._.defaults({}, config, player.config.default_options, this.defaults),
         _this = this;
     
     IriSP._(_config).forEach(function(_value, _key) {
@@ -1463,7 +1301,7 @@
     });
     
     if (typeof this.width === "undefined") {
-        this.width = player.config.gui.width;
+        this.width = player.config.width;
     }
     
     /* Setting this.player at the end in case it's been overriden
@@ -1476,6 +1314,15 @@
     
     /* Call draw when loaded */
     this.source.onLoad(function() {
+        if (_this.media_id) {
+            _this.media = this.getElement(_this.media_id);
+        } else {
+            var _mediaopts = {
+                is_mashup: _this.is_mashup || false
+            }
+            _this.media = this.getCurrentMedia(_mediaopts);
+        }
+        
         _this.draw();
     });
    
@@ -1517,36 +1364,61 @@
             return _function.apply(_this, Array.prototype.slice.call(arguments, 0));
         }
     } else {
-        console.log("Error, Unknown function IriSP." + this.type + "." + _name)
+        console.log("Error, Unknown function IriSP.Widgets." + this.type + "." + _name)
+    }
+}
+
+IriSP.Widgets.Widget.prototype.getFunctionOrName = function(_functionOrName) {
+    switch (typeof _functionOrName) {
+        case "function":
+            return _functionOrName;
+        case "string":
+            return this.functionWrapper(_functionOrName);
+        default:
+            return undefined;
     }
 }
 
-IriSP.Widgets.Widget.prototype.bindPopcorn = function(_popcornEvent, _functionName) {
-    this.player.popcorn.listen(_popcornEvent, this.functionWrapper(_functionName))
+IriSP.Widgets.Widget.prototype.onMdpEvent = function(_eventName, _functionOrName) {
+    this.player.on(_eventName, this.getFunctionOrName(_functionOrName));
+}
+
+IriSP.Widgets.Widget.prototype.onMediaEvent = function(_eventName, _functionOrName) {
+    this.media.on(_eventName, this.getFunctionOrName(_functionOrName));
 }
 
 IriSP.Widgets.Widget.prototype.getWidgetAnnotations = function() {
-    var _curmedia = this.source.currentMedia;
-    return typeof this.annotation_type !== "undefined" && this.annotation_type ? _curmedia.getAnnotationsByTypeTitle(this.annotation_type) : _curmedia.getAnnotations();
+    return typeof this.annotation_type !== "undefined" && this.annotation_type ? this.media.getAnnotationsByTypeTitle(this.annotation_type) : this.media.getAnnotations();
 }
 
 IriSP.Widgets.Widget.prototype.getWidgetAnnotationsAtTime = function() {
-    var _time = Math.floor(this.player.popcorn.currentTime() * 1000);
+    var _time = this.media.getCurrentTime();
     return this.getWidgetAnnotations().filter(function(_annotation) {
         return _annotation.begin <= _time && _annotation.end > _time;
     });
 }
 
-IriSP.Widgets.Widget.prototype.insertSubwidget = function(_selector, _propname, _widgetoptions) {
+IriSP.Widgets.Widget.prototype.insertSubwidget = function(_selector, _widgetoptions, _propname) {
     var _id = _selector.attr("id"),
-        _this = this;
+        _this = this,
+        _type = _widgetoptions.type,
+        $L = $LAB;
     if (typeof _id == "undefined") {
         _id = IriSP._.uniqueId(this.container + '_sub_widget_' + _widgetoptions.type);
         _selector.attr("id", _id);
     }
     _widgetoptions.container = _id;
-    _this.player.loadWidget(_widgetoptions, function(_widget) {
-        _this[_propname] = _widget;
+    if (typeof IriSP.widgetsRequirements[_type] !== "undefined" && typeof IriSP.widgetsRequirements[_type].requires !== "undefined" ) {
+        for (var _j = 0; _j < IriSP.widgetsRequirements[_type].requires.length; _j++) {
+            $L.script(IriSP.getLib(IriSP.widgetsRequirements[_type].requires[_j]));
+        }
+    }
+    $L.wait(function() {
+        _this.player.loadWidget(_widgetoptions, function(_widget) {
+            if (_propname) {
+                _this[_propname] = _widget;
+            }
+        });
     });
 }
 
@@ -1555,641 +1427,6 @@
  */
 IriSP.Widgets.Widget.prototype.draw = function() {
     /* implemented by "sub-classes" */
-};/* To wrap a player the develop should create a new class derived from
-the IriSP.PopcornReplacement.player and defining the correct functions */
-
-/** allocine player wrapper */
-IriSP.PopcornReplacement.allocine = function(container, options) {
-//    console.log("Calling allocine player");
-    /* appel du parent pour initialiser les structures communes à tous les players */
-    IriSP.PopcornReplacement.player.call(this, container, options);   
-    
-    var _this = this;
-
-    /* Définition des fonctions de l'API -  */
-
-    this.playerFns = {
-        play : function() {
-            return _this.apiCall("play");
-        },
-        pause : function() {
-            return _this.apiCall("pause");
-        },
-        getPosition : function() {
-            return _this.apiCall("getSeek","return") || 0;
-        },
-        seek : function(pos) {
-            return _this.apiCall("seek",pos);
-        },
-        getMute : function() {
-            return _this.apiCall("getMute","return");
-        },
-        setMute : function(p) {
-            return _this.apiCall("setMute", p);
-        }
-    }
-
-    window.onReady = function() {
-        _this.ready();
-    };
-    window.onAllocineStateChange = function(_state) {
-        _this.stateHandler(_state)
-    }
-    window.onTime = function(_progress) {
-        _this.progressHandler(_progress)
-    };
-    
-    var _flashVars = {
-        "streamFMS" : true,
-        "adVast" : false,
-        "lg" : "fr_cinecast",
-        "autoPlay" : options.autoPlay,
-        "directVideoTitle" : "",
-        "urlAcData" : options.urlAcData,
-        "directVideoPath" : options.video,
-        "host" : "http://allocine.fr"
-    }
-    
-    if (typeof IriSP.__jsonMetadata["medias"][0].meta == "object" && typeof IriSP.__jsonMetadata["medias"][0].meta.subtitles == "string") {
-        _flashVars.subTitlePath = IriSP.__jsonMetadata["medias"][0].meta.subtitles;
-    }
-    
-
-    var params = {
-        "allowScriptAccess" : "always",
-        "wmode": "opaque",
-        "flashvars" : IriSP.jQuery.param(_flashVars),
-        "allowfullscreen" : true
-    };
-    var atts = {
-        id : this.container
-    };
-    swfobject.embedSWF(options.acPlayerUrl, this.container, options.width, options.height, "10", null, null, params, atts);
-
-};
-
-IriSP.PopcornReplacement.allocine.prototype = new IriSP.PopcornReplacement.player("", {});
-
-IriSP.PopcornReplacement.allocine.prototype.ready = function() {
-    this.player = document.getElementById(this.container);
-    this.player.addEventListener("onStateChange", "onAllocineStateChange");
-    this.player.cueVideoByUrl(this._options.video);
-    this.trigger("loadedmetadata");
-};
-
-IriSP.PopcornReplacement.allocine.prototype.progressHandler = function(progressInfo) {
-    this.trigger("timeupdate");
-}
-
-
-IriSP.PopcornReplacement.allocine.prototype.apiCall = function(_method, _arg) {
-    if (this.player) {
-        try {
-            if (typeof _arg == "undefined") {
-                return this.player.sendToActionScript(_method);
-            } else {
-                return this.player.sendToActionScript(_method, _arg);
-            }
-        } catch(e) {
-            console.error('Exception while requesting AcPlayer for "' + _method + (typeof _arg == "undefined" ? '' : '" with argument "' + _arg ) + '"\n', e);
-            return false;
-        }
-    } else {
-        return false;
-    }
-}
-
-IriSP.PopcornReplacement.allocine.prototype.stateHandler = function(state) {
-    switch(state) {
-        case 1:
-            this.trigger("play");
-            break;
-
-        case 2:
-            this.trigger("pause");
-            break;
-
-        case 3:
-            this.trigger("seeked");
-            break;
-    }
-    
-};/* To wrap a player the develop should create a new class derived from
-the IriSP.PopcornReplacement.player and defining the correct functions */
-
-/** jwplayer player wrapper */
-IriSP.PopcornReplacement.dailymotion = function(container, options) {
-    /* Appel du constructeur de la classe parente */
-    IriSP.PopcornReplacement.player.call(this, container, options);   
-    
-    var _this = this;
-
-    /* Définition des fonctions de commande :
-     this.playerFns.play, .pause, .getPosition, .seek,
-     .getMute, .setMute, .getVolume, .setVolume
-     doivent être rattachés aux fonctions du player
-     * */
-
-    this.playerFns = {
-        play : function() {
-            if (_this.player) {
-                return _this.player.playVideo();
-            } else {
-                return false;
-            }
-        },
-        pause : function() {
-            if (_this.player) {
-                return _this.player.pauseVideo();
-            } else {
-                return false;
-            }
-        },
-        getPosition : function() {
-            if (_this.player) {
-                return _this.player.getCurrentTime();
-            } else {
-                return 0;
-            }
-        },
-        seek : function(pos) {
-            if (_this.player) {
-                return _this.player.seekTo(pos);
-            } else {
-                return false;
-            }
-        },
-        getMute : function() {
-            if (_this.player) {
-                return _this.player.isMuted();
-            } else {
-                return false;
-            }
-        },
-        setMute : function(p) {
-            if (_this.player) {
-                if (p) {
-                    _this.player.mute();
-                }
-                else {
-                    _this.player.unMute();
-                }
-            }
-        },
-        getVolume : function() {
-            if (_this.player) {
-                return _this.player.getVolume() / 100;
-            } else {
-                return false;
-            }
-        },
-        setVolume : function(p) {
-            if (_this.player) {
-                _this.player.setVolume(Math.floor(100 * p));
-            }
-        },
-    }
-    
-    /* Dailymotion utilise un système de fonctions référencées dans
-     * des variables globales pour la gestion des événements.
-     */
-    
-    window.onDailymotionPlayerReady = function() {
-        _this.onReady();
-    };
-    window.onDailymotionStateChange = function(_state) {
-        _this.onStateChange(_state);
-    }
-    window.onDailymotionVideoProgress = function(_progress) {
-        _this.onProgress(_progress);
-    }
-
-    var params = {
-        "allowScriptAccess" : "always",
-        "wmode": "opaque"
-    };
-    var atts = {
-        id : this.container
-    };
-    swfobject.embedSWF("http://www.dailymotion.com/swf?chromeless=1&enableApi=1", this.container, options.width, options.height, "8", null, null, params, atts);
-
-};
-
-IriSP.PopcornReplacement.dailymotion.prototype = new IriSP.PopcornReplacement.player("", {});
-
-IriSP.PopcornReplacement.dailymotion.prototype.onReady = function() {
-    
-    this.player = document.getElementById(this.container);
-    
-    this.player.addEventListener("onStateChange", "onDailymotionStateChange");
-    this.player.addEventListener("onVideoProgress", "onDailymotionVideoProgress");
-    this.player.cueVideoByUrl(this._options.video);
-    
-    this.trigger("loadedmetadata");
-};
-
-IriSP.PopcornReplacement.dailymotion.prototype.onProgress = function(progressInfo) {
-    this.trigger("timeupdate");
-}
-
-IriSP.PopcornReplacement.dailymotion.prototype.onStateChange = function(state) {
-    
-    switch(state) {
-        case 1:
-            this.trigger("play");
-            break;
-
-        case 2:
-            this.trigger("pause");
-            break;
-
-        case 3:
-            this.trigger("seeked");
-            break;
-    }
-    
-};/* To wrap a player the develop should create a new class derived from 
-   the IriSP.PopcornReplacement.player and defining the correct functions */
-
-/** jwplayer player wrapper */
-IriSP.PopcornReplacement.jwplayer = function(container, options) {
-    /* appel du parent pour initialiser les structures communes à tous les players */
-    IriSP.PopcornReplacement.player.call(this, container, options);
-    
-    if (options.autostart) {
-        this.media.paused = false;
-        this.trigger("play");
-    }
- 
-    var _player = jwplayer(this.container),
-        _this = this,
-        _seekPause = false;
-  
-  /* Définition des fonctions de l'API -  */
-    this.playerFns = {
-        play: function() { return _player.play(true); },
-        pause: function() { return _player.pause(true); },
-        getPosition: function() { return _player.getPosition(); },
-        seek: function(pos) {
-            _seekPause = _this.media.paused;
-            return _player.seek(pos);
-        },
-        getMute: function() { return _player.getMute() },
-        setMute: function(p) { return _player.setMute(p); },
-        getVolume: function() { return _player.getVolume() / 100; },
-        setVolume: function(p) { return _player.setVolume(Math.floor(100*p)); }
-    }
-
-    options.events = {
-        onReady:  function() {
-            _this.trigger("loadedmetadata");
-        },
-        onTime:   function() {
-            if (_seekPause) {
-                _player.pause(true);
-                _seekPause = false;
-            } else {
-                if (_this.media.paused && _player.getState() === "PLAYING") {
-                    _this.media.paused = false;
-                    _this.trigger("play");
-                }
-            }
-            _this.trigger("timeupdate");
-        },
-        onPlay:   function() {
-            if (!_seekPause) {
-                _this.media.paused = false;
-                _this.trigger("play");
-            }
-        },
-        onPause:  function() {
-            _this.media.paused = true;
-            _this.trigger("pause");
-        },
-        onSeek:   function() {
-            _this.trigger("seeked");
-        }
-    };
-
-    _player.setup(options);
-};
-
-IriSP.PopcornReplacement.jwplayer.prototype = new IriSP.PopcornReplacement.player("", {});
-/* To wrap a player the develop should create a new class derived from 
-   the IriSP.PopcornReplacement.player and defining the correct functions */
-
-/** jwplayer player wrapper */
-IriSP.PopcornReplacement.htmlMashup = function(container, options, metadata) {
-    /* appel du parent pour initialiser les structures communes à tous les players */
-    IriSP.PopcornReplacement.player.call(this, container, options);
-    
-    this.mashup = metadata.currentMedia;
-    this.$ = IriSP.jQuery(container);
-    
-    var _w = this.$.width(),
-        _h = this.$.height(),
-        _this = this;
-    
-    IriSP._(metadata.currentMedia.medias).each(function(_media) {
-        var _tmpId = Popcorn.guid("video"),
-            _videoEl = IriSP.jQuery('<video>'),
-            _videoUrl = _media.video;
-        if (typeof options.url_transform === "function") {
-            _videoUrl = options.url_transform(_videoUrl);
-        }
-        
-        _videoEl
-            .attr({
-                src : _videoUrl,
-                id : _tmpId,
-                width : _w,
-                height : _h
-            })
-            .css({
-                position: "absolute",
-                top: 0,
-                left: 0
-            });
-
-        _this.$.append(_videoEl);
-        _media.videoEl = _videoEl;
-        _media.popcorn = Popcorn("#" + _tmpId);
-        _media.loadedMetadata = false;
-        _media.popcorn.on("loadedmetadata", function() {
-            _media.loadedMetadata = true;
-            var _allLoaded = true;
-            for (var _i = 0; _i < metadata.currentMedia.medias.length; _i++) {
-                _allLoaded = _allLoaded && metadata.currentMedia.medias[_i].loadedMetadata;
-            }
-            if (_allLoaded) {
-                _this.changeCurrentAnnotation();
-                _this.trigger("loadedmetadata");
-            }
-        });
-        _media.popcorn.on("timeupdate", function() {
-            if (!_this.media.paused && _media === _this.currentMedia) {
-                var _time = Math.round( 1000 * _media.popcorn.currentTime() );
-//                var _status = "Timeupdate from " + _media.id + " at time " + _time;
-                if ( _time < _this.segmentEnd ) {
-                    if ( _time >= _this.segmentBegin ) {
-                        _this.timecode = _time - _this.timedelta;
-//                        _status += " within segment";
-                    } else {
-                        _this.timecode = _this.segmentBegin - _this.timedelta;
-                        _media.popcorn.currentTime(_this.segmentBegin / 1000);
-//                        _status += " before segment";
-                    }
-                } else {
-                    _this.timecode = _this.segmentEnd - _this.timedelta;
-                    _media.popcorn.pause();
-                    _this.changeCurrentAnnotation();
-//                    _status += " after segment";
-                }
-//                _status += " (" + _this.segmentBegin + " to " + _this.segmentEnd + ")" + ", translated to " + _this.timecode;
-//                console.log(_status);
-                _this.trigger("timeupdate");
-            }
-        });
-    });
-    
-    this.timecode = 0;
-  
-  /* Définition des fonctions de l'API */
-    this.playerFns = {
-        play: function() {
-            _this.changeCurrentAnnotation();
-        },
-        pause: function() {
-            _this.currentMedia.popcorn.pause();
-        },
-        getPosition: function() {
-            return _this.timecode / 1000;
-        },
-        seek: function(pos) {
-            _this.timecode = Math.round(pos * 1000);
-            _this.changeCurrentAnnotation();
-        },
-        getMute: function() {
-            var _res = (
-                typeof _this.currentMedia !== "undefined"
-                ? _this.currentMedia.popcorn.muted()
-                : false
-            );
-            return _res;
-        },
-        setMute: function(p) {
-            var _mute = !!p;
-            for (var _i = 0; _i < _this.mashup.medias.length; _i++) {
-                _this.mashup.medias[_i].popcorn.muted(_mute);
-            }
-        },
-        getVolume: function() {
-            var _res = (
-                typeof _this.currentMedia !== "undefined"
-                ? _this.currentMedia.popcorn.volume()
-                : .5
-            );
-            return _res;
-        },
-        setVolume: function(_vol) {
-            for (var _i = 0; _i < _this.mashup.medias.length; _i++) {
-                _this.mashup.medias[_i].popcorn.volume(_vol);
-            }
-        }
-    }
-    
-};
-
-IriSP.PopcornReplacement.htmlMashup.prototype = new IriSP.PopcornReplacement.player("", {});
-
-IriSP.PopcornReplacement.htmlMashup.prototype.changeCurrentAnnotation = function() {
-    var _annotation = this.mashup.getAnnotationAtTime( this.timecode );
-    if (typeof _annotation == "undefined") {
-        if (typeof this.currentMedia !== "undefined") {
-            this.currentMedia.popcorn.pause();
-            if (!this.media.paused) {
-                this.media.paused = true;
-                this.trigger("pause");
-            }
-        }
-        return;
-    }
-    if (_annotation !== this.currentAnnotation) {
-        this.currentAnnotation = _annotation;
-        this.segmentBegin = this.currentAnnotation.annotation.begin.milliseconds;
-        this.segmentEnd = this.currentAnnotation.annotation.end.milliseconds;
-        this.timedelta = this.segmentBegin - this.currentAnnotation.begin.milliseconds;
-        this.currentMedia = this.currentAnnotation.getMedia();
-        
-        for (var _i = 0; _i < this.mashup.medias.length; _i++) {
-            if (this.mashup.medias[_i].id !== this.currentMedia.id) {
-                this.mashup.medias[_i].videoEl.hide();
-                this.mashup.medias[_i].popcorn.pause();
-            } else {
-                this.mashup.medias[_i].videoEl.show();
-            }
-        }
-/* PRELOADING */
-        var _this = this,
-            _preloadedMedias = [],
-            _toPreload = this.mashup.getAnnotations().filter(function(_a) {
-            return (_a.begin >= _this.currentAnnotation.end && _a.getMedia().id !== _this.currentMedia.id);
-        });
-        IriSP._(_toPreload).each(function(_a) {
-            var _media = _a.getMedia();
-            if (IriSP._(_preloadedMedias).indexOf(_media.id) === -1) {
-                _preloadedMedias.push(_media.id);
-                _media.popcorn.currentTime(_a.annotation.begin.getSeconds());
-                //console.log("Preloading ", _media.id, " at t=", _a.annotation.begin.getSeconds());
-            }
-        });
-        
-//        console.log("Changed segment: media="+ this.currentMedia.id + ", from=" + this.segmentBegin + " to=" + this.segmentEnd +", timedelta = ", this.timedelta)
-//    } else {
-//        console.log("changeCurrentAnnotation called, but segment hasn't changed");
-    }
-    if (this.currentMedia.popcorn.readyState()) {
-        this.currentMedia.popcorn.currentTime( (this.timecode + this.timedelta) / 1000);
-        this.trigger("timeupdate");
-    }
-    if (!this.media.paused) {
-        this.currentMedia.popcorn.play();
-    }
-}
-/* To wrap a player the develop should create a new class derived from
-the IriSP.PopcornReplacement.player and defining the correct functions */
-
-/** jwplayer player wrapper */
-IriSP.PopcornReplacement.mashup = function(container, options) {
-    /* Appel du constructeur de la classe parente */
-    IriSP.PopcornReplacement.player.call(this, container, options);   
-
-    var _this = this;
-
-    /* Définition des fonctions de commande :
-     this.playerFns.play, .pause, .getPosition, .seek,
-     .getMute, .setMute, .getVolume, .setVolume
-     doivent être rattachés aux fonctions du player
-     * */
-
-    this.playerFns = {
-        play : function() {
-            if (_this.player) {
-                return _this.player.playVideo();
-            } else {
-                return false;
-            }
-        },
-        pause : function() {
-            if (_this.player) {
-                return _this.player.pauseVideo();
-            } else {
-                return false;
-            }
-        },
-        getPosition : function() {
-            if (_this.player) {
-                return _this.player.getCurrentTime();
-            } else {
-                return 0;
-            }
-        },
-        seek : function(pos) {
-            if (_this.player) {
-                return _this.player.seekTo(pos);
-            } else {
-                return false;
-            }
-        },
-        getMute : function() {
-            if (_this.player) {
-                return _this.player.isMuted();
-            } else {
-                return false;
-            }
-        },
-        setMute : function(p) {
-            if (_this.player) {
-                if (p) {
-                    _this.player.mute();
-                }
-                else {
-                    _this.player.unMute();
-                }
-            }
-        },
-        getVolume : function() {
-            if (_this.player) {
-                return _this.player.getVolume() / 2;
-            } else {
-                return false;
-            }
-        },
-        setVolume : function(p) {
-            if (_this.player) {
-                _this.player.setVolume(Math.floor(2 * p));
-            }
-        },
-    }
-    
-    /* Dailymotion utilise un système de fonctions référencées dans
-     * des variables globales pour la gestion des événements.
-     */
-    
-    window.onBabPlayerReady = function() {
-        _this.onReady();
-    };
-    window.onBabStateChange = function(_state) {
-        _this.onStateChange(_state);
-    }
-    window.onBabVideoProgress = function(_progress) {
-        _this.onProgress(_progress);
-    }
-
-    var params = {
-        allowScriptAccess : "always",
-        wmode: "transparent",
-        quality: "high",
-        menu: true,
-        bgcolor: "#869ca7"
-    };
-    var atts = {
-        id : this.container
-    };
-    var flashvars = {
-        urlData: options.mashup_xml
-    };
-    swfobject.embedSWF(options.mashup_swf, this.container, options.width, options.height, "8", null, flashvars, params, atts);
-
-};
-
-IriSP.PopcornReplacement.mashup.prototype = new IriSP.PopcornReplacement.player("", {});
-
-IriSP.PopcornReplacement.mashup.prototype.onReady = function() {
-    this.player = document.getElementById(this.container);
-    this.trigger("loadedmetadata");
-};
-
-IriSP.PopcornReplacement.mashup.prototype.onProgress = function(progressInfo) {
-    this.trigger("timeupdate");
-}
-
-IriSP.PopcornReplacement.mashup.prototype.onStateChange = function(state) {
-
-    switch(state) {
-        case 1:
-            this.trigger("play");
-            break;
-
-        case 2:
-            this.trigger("pause");
-            break;
-
-        case 3:
-            this.trigger("seeked");
-            break;
-    }
-
 };/* LDT Platform Serializer */
 
 if (typeof IriSP.serializers === "undefined") {
@@ -2400,7 +1637,7 @@
         }
         
         if (typeof _data.meta !== "undefined" && typeof _data.meta.main_media !== "undefined" && typeof _data.meta.main_media["id-ref"] !== "undefined") {
-            _source.mainMedia = _data.meta.main_media["id-ref"];
+            _source.currentMedia = _source.getElement(_data.meta.main_media["id-ref"]);
         }
     }
 }