var ultimediaPlayer={
    playerDivID:'',
    overlayDivID:'',
    overlay:'<div id="#overlayDivID#" style="position:absolute;width:#width#px;height:#height#px;background:#000;filter:alpha(opacity=0);-moz-opacity:0;opacity:0;cursor:pointer;" onclick="startad();"></div>',
    adDivID:'',
   adCode:'<embed id="nouvelobs_ultimedia" name="nouvelobs_ultimedia" data="http://www.ultimedia.com/swf/ultimedia-player.swf" src="http://www.ultimedia.com/swf/ultimedia-player.swf" width="#adWidth#" height="#adHeight#" allowscriptaccess="always" allowfullscreen="true" flashvars="screenColor=000000&dock=true&plugins=http://www.ultimedia.com/swf/ova.swf&config=http://www.ultimedia.com/deliver/musique/getcampaignxml/url_campaign/http%25253A%25252F%25252Ffr-advideum.videoplaza.tv%25252Fproxy%25252Fdistributor%25253Ftt%25253Dpreroll%252526tags%25253Dnews%25252Ccsp%25252B%25252Cfem%252526shares%25253Dobsstyle%252526flags%25253D%252526rnd%25253D%25255BRANDOM%25255D%252526accepts%25253Dvast_2.0/autoplayad/#adAutoplay#&amp;file=http%3A%2F%2Fwww.jukebo.fr%2Fswf%2Fvideo.flv&amp;image=&amp;autostart=true&file=http%3A%2F%2Fwww.jukebo.fr%2Fswf%2Fvideo.flv&image=&autostart=true" style="position:absolute" wmode="transparent" allowScriptAccess="always" type="application/x-shockwave-flash"></embed>',
    
    urlXMLAd:'http://fr-advideum.videoplaza.tv/proxy/distributor?tt=preroll&tags=news,csp+,fem&shares=obsstyle&flags=&rnd=[RANDOM]&accepts=vast_2.0',
    adWidth:0,//px
    adHeight:0,//px
    adAutoplay:0,//0/1
    videoDivID:'',
    videoURL:'',
    videoAutoPlay:1,//0/1
    videoFullScreen:true,//false/true
    videoScriptAccess:'sameDomain',//always/sameDomain/never
    videoWmode:'transparent',//window/opaque/transparent 
    videoEmbed:'<embed id="#videoDivID#" type="application/x-shockwave-flash" src="#videoSrc#" width="#width#" height="#height#" allowfullscreen="#videoFullScreen#" allowscriptaccess="#videoScriptAccess#" wmode="#videoWmode#" />',
    width:480,//px
    height:385,//px
    partnerMDTK:0,

    show:function(_videoURL,_partnerMDTK){
		this.adWidth = this.width;
		this.adHeight = (this.height-20);
        this.videoURL=_videoURL||this.videoURL;
        this.partnerMDTK=_partnerMDTK||this.partnerMDTK;
        this.playerDivID='ultimediaPlayerDiv';
        this.overlayDivID='ultimediaPlayerOverlay';
        this.overlay=this.overlay.replace(/#overlayDivID#/,this.overlayDivID);
        this.overlay=this.overlay.replace(/#width#/,this.width);
        this.overlay=this.overlay.replace(/#height#/,this.height);
        this.adDivID='ultimediaPlayerAd';
        this.adTextDivID='ultimediaPlayerAdText';
        if(this.adWidth==0){
            this.adWidth=Math.round(this.width*0.70833333333333333333333333333333);//default width:340
        }
        if(this.adHeight==0){
            this.adHeight=Math.round(this.height*0.72727272727272727272727272727273);//default height:280
        }
        this.adCode=this.adCode.replace(/#adWidth#/g,this.adWidth);
        this.adCode=this.adCode.replace(/#adHeight#/g,this.adHeight+6);
        this.adCode=this.adCode.replace(/#adAutoplay#/g,this.adAutoplay);    
        document.write('<div id="'+this.playerDivID+'" style="width:'+this.width+'px;height:'+this.height+'px;position:relative;background:#000;font:normal 10px verdana;color:#fff;">'+this.overlay+this.getVideoEmbed()+'<div id="'+this.adDivID+'" style="width:'+this.width+'px;height:'+this.height+'px;text-align:left;display:none;"><div id="'+this.adTextDivID+'" style="padding:2px 0 2px 0;visibility:hidden;">Votre vid&eacute;o commence apr&egrave;s la pub.</div><div>'+this.adCode+'</div></div></div>');
        //httpGetRequest('http://www.ultimedia.com/js/jwplayer.js?v=1');
        if(this.adAutoplay==1){
            this.startAd();
        }
    },
    
    getVideoEmbed:function(){
        this.videoDivID='ultimediaPlayerVideo';
        this.videoEmbed=this.videoEmbed.replace(/#videoDivID#/,this.videoDivID);
        var videoID=0;
        var videoSrc='';
        if(/www.dailymotion.com/i.exec(this.videoURL)){
            videoID=/video\/([a-z0-9]+)_/i.exec(this.videoURL);
            videoSrc='http://www.dailymotion.com/swf/video/'+videoID[1]+'&autoplay=#videoAutoPlay#';
        }else if(/www.youtube.com/i.exec(this.videoURL)){
            videoID=/\?v=([a-z0-9-_]+)&?/i.exec(this.videoURL);
            videoSrc='http://www.youtube.com/v/'+videoID[1]+'&autoplay=#videoAutoPlay#';
        }
        this.videoEmbed=this.videoEmbed.replace(/#videoSrc#/,videoSrc);
        this.videoEmbed=this.videoEmbed.replace(/#videoAutoPlay#/,0);
        this.videoEmbed=this.videoEmbed.replace(/#width#/,this.width);
        this.videoEmbed=this.videoEmbed.replace(/#height#/,this.height);
        this.videoEmbed=this.videoEmbed.replace(/#videoFullScreen#/,this.videoFullScreen);
        this.videoEmbed=this.videoEmbed.replace(/#videoScriptAccess#/,this.videoScriptAccess);
        this.videoEmbed=this.videoEmbed.replace(/#videoWmode#/,this.videoWmode);

        return this.videoEmbed;
    },

    startAd:function(){
        document.getElementById(this.playerDivID).removeChild(document.getElementById(this.overlayDivID));
        document.getElementById(this.playerDivID).removeChild(document.getElementById(this.videoDivID));
        this.videoEmbed=this.videoEmbed.replace(/(&autoplay=)0/,'$1'+this.videoAutoPlay);
        document.getElementById(this.adDivID).style.display='block';
    },

    finishAd:function(){
        document.getElementById(this.playerDivID).innerHTML=this.videoEmbed;
    },

    logStat:function(adStatus){
        httpGetRequest('http://ultimediav1.digiteka.net/misc/stats_player.php?ad='+adStatus+'&video='+encodeURIComponent(this.videoURL)+'&partner='+this.partnerMDTK);
    }
}
function startad(){
    ultimediaPlayer.startAd();
}
function endad(){
    ultimediaPlayer.finishAd();
    ultimediaPlayer.logStat(1);
}
function noad(){
    ultimediaPlayer.finishAd();
    ultimediaPlayer.logStat(0);
}
function displaypub(){
    document.getElementById(ultimediaPlayer.adTextDivID).style.visibility='visible';
    ultimediaPlayer.logStat(2);
}
function httpGetRequest(fileURL){
    var script=document.createElement('script');
    script.type='text/javascript';
    script.src=fileURL+'&'+Math.round(Math.random()*100000);
    document.getElementById(ultimediaPlayer.playerDivID).appendChild(script);
}
function onVASTLoadSuccess(response){
    if(response.indexOf("MediaFiles")==-1){
        noad();
    }    
}
function onLinearAdFinish(){
    endad();
}

