﻿var item_sel = 0;
var last_url = '';

function thisMovieArchivage(swf) {
  if(navigator.appName.indexOf("Microsoft") != -1) {
    return window[swf];
  } else {
    return document[swf];
  }
};
function calculer_extension(strUrl){
    extension = "";
    if(strUrl){
        start = strUrl.lastIndexOf(".");                  //find the last period character in the string
        if (start == -1){                                //if there isn't one report the problem
          // document.writeln(errorMsg)
          extension = "";
        }
        else{
           start++;                                      //the first character of the extension is the one after the .
           
           extension = strUrl.substring(start, strUrl.length).toLowerCase();
        }
    }
    return extension;
}

function changer_emission_player(iItem, urlVideo,titre, TeasingLong){
    if(iItem != item_sel){
        // reinit style ancien
        if(item_sel>0)
            Element.classNames($('item-' + item_sel)).remove('bloc-archivage-liste-item-sel');
            
            
        // init style nouveau
        Element.classNames($('item-' + iItem)).add('bloc-archivage-liste-item-sel');
        // update modif url
        
        // si actuel = WMV
        if(calculer_extension(urlVideo) == "wmv"){
            charger_archivage_player_wmv(urlVideo);
         }
         else if(calculer_extension(last_url) == "flv"){
            // sinon si last_url = FLV (actuel = FLV) alors
            var obj = {file:urlVideo};
            var pl = $get('player_archivage');
            //alert(pl);
            if(pl)
            pl.loadFile(obj);
            /*if(thisMovieArchivage('player_archivage')){
                thisMovieArchivage('player_archivage').loadFile(obj);
            }*/
        }
        else{
            // sinon (actuel = FLV et last_url != flv)
            charger_archivage_player_flv(urlVideo);
        }
       
        // stockage nouveau
        item_sel = iItem;
        last_url = urlVideo;
        //if($('bloc-archivage-player-legende')){
       // $('bloc-archivage-player-legende').innerHTML = titre + '<br />' + TeasingLong;
        //}
    }
    else{
    }
    
    return false;
}
function charger_archivage_player_wmv(url){
var objConteneur = $('bloc-conteneur-archivage-player');
objConteneur.innerHtml = "";
objConteneur.innerHtml = '<!--[if IE]> \
            <object id="player_archivage" width="316" height="226" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" standby="Chargement du lecteur video en cours ..." type="application/x-oleobject" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112">\
                    <param name="url" value="' + url + '" />\
                    <param name="Showcontrols" value="true" />\
                    <param name="autoStart" value="true" />\
                    <param name="stretchToFit" value="true" />\
                    <param name="uiMode" value="mini" />\
                    <embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/"  src="' + url + '" name="player_archivage" width="316" height="226" stretchToFit="true" uiMode="mini"><param name="stretchToFit" value="true" />\
                    <param name="uiMode" value="mini" /></embed>\
</object>\
            <![endif]--><!--[if !IE]> <-->\
<object id="player_archivage" width="316" height="226" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" standby="Chargement du lecteur video en cours ..." type="application/x-oleobject" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112">\
                    <param name="url" value="' + url + '" />\
                    <param name="Showcontrols" value="true" />\
                    <param name="autoStart" value="true" />\
                    <param name="stretchToFit" value="true" />\
                    <param name="uiMode" value="mini" />\
                    <embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/"  src="' + url +'" name="player_archivage" width="316" height="226" stretchToFit="true" uiMode="mini"><param name="stretchToFit" value="true" />\
                    <param name="uiMode" value="mini" /></embed>\
</object>\
  <!--> <![endif]-->';
}

function charger_archivage_player_flv(url){
 var so_player_archivage = new SWFObject("/flash/mediaplayer.swf", "player_archivage", "316", "226", "7", "");
    so_player_archivage.addParam("wmode", "transparent");
    so_player_archivage.addParam("quality", "high");
    so_player_archivage.addParam("allowscriptaccess", "always");
    so_player_archivage.addParam("play", "true");so_player_archivage.addParam("allowFullScreen","true");
    so_player_archivage.addVariable("file",url);
    so_player_archivage.addVariable("volume","75");
    so_player_archivage.addVariable("autostart","true");
    so_player_archivage.addVariable("backcolor","0x5E5E5E");
    so_player_archivage.addVariable("frontcolor","0xffffff");
    so_player_archivage.addVariable("width","316");
    so_player_archivage.addVariable("height","226");
    so_player_archivage.addVariable("enablejs","true");
    so_player_archivage.addVariable("javascriptid","player_archivage");
    so_player_archivage.write("bloc-conteneur-archivage-player");
}