// <!--
/* Audio creator v1.0
 * Copyright 2005 - francisek.over-blog.com, Apple inc.
 * Selectionne le lecteur multimédia approprié
 * et permet de changer le fichier lu (depuis un lien)
 * CONFIGURATION : Voir en fin de ce fichier.
 */

var detectableWithVB = false;
var useActiveX = false;
if ((navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1)) {
    document.writeln('<script language="VBscript">');
    document.writeln('\'do a one-time test for a version of VBScript that can handle this code');
    document.writeln('detectableWithVB = False');
    document.writeln('If ScriptEngineMajorVersion >= 2 then');
    document.writeln('  detectableWithVB = True');
    document.writeln('End If');

    document.writeln('\'this next function will detect most plugins');
    document.writeln('Function detectActiveXControl(activeXControlName)');
    document.writeln('  on error resume next');
    document.writeln('  detectActiveXControl = False');
    document.writeln('  If detectableWithVB Then');
    document.writeln('     If IsObject(CreateObject(activeXControlName)) Then detectActiveXControl = 2 else detectActiveXControl = 0');
    document.writeln('  End If');
    document.writeln('End Function');

    document.writeln('\'and the following function handles QuickTime');
    document.writeln('Function detectQuickTimeActiveXControl()');
    document.writeln('  on error resume next');
    document.writeln('  detectQuickTimeActiveXControl = False');
    document.writeln('  If detectableWithVB Then');
    document.writeln('    detectQuickTimeActiveXControl = False');
    document.writeln('    hasQuickTimeChecker = false');
    document.writeln('    Set hasQuickTimeChecker = CreateObject("QuickTimeCheckObject.QuickTimeCheck.1")');
    document.writeln('    If IsObject(hasQuickTimeChecker) Then');
    document.writeln('      If hasQuickTimeChecker.IsQuickTimeAvailable(0) Then ');
    document.writeln('        detectQuickTimeActiveXControl = True');
    document.writeln('      End If');
    document.writeln('    End If');
    document.writeln('  End If');
    document.writeln('End Function');

    document.writeln('</scr' + 'ipt>');
}


function MultimediaPlayer(p_conteneur, p_url, p_mime) {
 this.hasReal = false;
 this.hasQuickTime = false;
 this.hasWMP = false;
 this._url = p_url;
 this.mime = p_mime;
 this._autostart = true;
 this._loop = false;
 this._width=175;
 this._height=30;
 this.conteneur = p_conteneur;
 this.aLinks = null;

 this.AutoStart = function(p_as) {
  this._autostart = p_as;
 };
 this.Boucle = function(p_loop) {
  this._loop = p_loop;
 };
 this.canDetectPlugins = function () {
  if( detectableWithVB || (navigator.plugins && navigator.plugins.length > 0))
  return true;
  return false;
 };

 this.AjoutePiste = function(p_url, p_mime, p_texte) {
  if (this.aLinks == null) this.aLinks = new Array();
  this.aLinks[this.aLinks.length] = new Array(p_url, p_mime, p_texte);
 };

 this._creeLiens = function() {
  var str = '';
  if (this.aLinks != null) {
    str = '<div class="PlayerLinks">';
  for(var i=0; i< this.aLinks.length; i++)
    str += '<a href="javascript:'+this.conteneur+'.ChangeURL(\''
    +this.aLinks[i][0]+'\', \''+this.aLinks[i][1]+'\');">'
    +this.aLinks[i][2]+'</a><br/>';
  str += '</div>';
  }
  return str;
 };

 this.detectPlugin = function() {
    // allow for multiple checks in a single pass
    var daPlugins = this.detectPlugin.arguments;
    // consider pluginFound to be false until proven true
    var pluginFound = false;
    // if plugins array is there and not fake
    if (navigator.plugins && navigator.plugins.length > 0) {
	var pluginsArrayLength = navigator.plugins.length;
	// for each plugin...
	for (var pluginsArrayCounter=0; pluginsArrayCounter < pluginsArrayLength; pluginsArrayCounter++ ) {
	    // loop through all desired names and check each against the current plugin name
	    var numFound = 0;
	    for(var namesCounter=0; namesCounter < daPlugins.length; namesCounter++) {
		// if desired plugin name is found in either plugin name or description
		if( (navigator.plugins[pluginsArrayCounter].name.indexOf(daPlugins[namesCounter]) >= 0) ||
		    (navigator.plugins[pluginsArrayCounter].description.indexOf(daPlugins[namesCounter]) >= 0) ) {
		    // this name was found
		    numFound++;
		}
	    }
	    // now that we have checked all the required names against this one plugin,
	    // if the number we found matches the total number provided then we were successful
	    if(numFound == daPlugins.length) {
		pluginFound = 1;
		// if we've found the plugin, we can stop looking through at the rest of the plugins
		break;
	    }
	}
    }
    return pluginFound;
}; // detectPlugin

 this.detectQuickTime = function() {
    this.hasQuickTime = this.detectPlugin('QuickTime');
    // if not found, try to detect with VisualBasic
    if(!this.hasQuickTime && detectableWithVB) {
	  this.hasQuickTime = detectQuickTimeActiveXControl();
    }
 };

 this.detectWMP = function() {
    this.hasWMP = this.detectPlugin('Windows Media');
    // if not found, try to detect with VisualBasic
    if(!this.hasWMP && detectableWithVB) {
	this.hasWMP = detectActiveXControl('MediaPlayer.MediaPlayer.1');
    }
 };

 this.detectReal = function() {
    this.hasReal = this.detectPlugin('RealPlayer');
    // if not found, try to detect with VisualBasic
    if(!this.hasReal && detectableWithVB) {
	this.hasReal = (detectActiveXControl('rmocx.RealPlayer G2 Control') ||
       detectActiveXControl('RealPlayer.RealPlayer(tm) ActiveX Control (32-bit)') ||
       detectActiveXControl('RealVideo.RealVideo(tm) ActiveX Control (32-bit)'));
    }
 };
 this.detectWMP();
 this.detectReal();
 this.detectQuickTime();
 
 this.makeSound = function(player) {
  this._autostart = this._autostart ? 'true' : 'false';
  this._loop = this._loop ? 'true' : 'false';
  var str = new String();
  if (player==1 && this.hasQuickTime) {
    // QuickTime
      str = '<OBJECT ID="FSKOPlayer_'+this.conteneur+'"'
      +' CLASSID="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" WIDTH="'+this._width+'" HEIGHT="'+this._height+'" CODEBASE="http://www.apple.com/qtactivex/qtplugin.cab">'
      +'<PARAM name="SRC" VALUE="'+this._url+'">'
      +'<PARAM name="AUTOPLAY" VALUE="'+this._autostart+'">'
      +'<PARAM name="LOOP" VALUE="'+this._loop+'">'
      +'<PARAM name="CONTROLLER" VALUE="true">'
      +'<PARAM name="enablejavascript" VALUE="true">'
      +'<EMBED SRC="'+this._url+'"' // +'TYPE="'+this._mime+'"'  
      +' AUTOSTART="'+this._autostart+'" LOOP="'+this._loop+'"'
      +' WIDTH="'+this._width+'px" HEIGHT="'+this._height+'px"'
      +' enablejavascript=true bgcolor=transparent'
      +' NAME=FSKOPlayer_'+this.conteneur+'></EMBED>'
      +'</OBJECT>';
       this.ChangeURL = function(p_URL) {
        try {
          this._url = p_URL;
         eval('document.FSKOPlayer_'+this.conteneur+'.SetURL(p_URL);');
        } catch(err) {};
       };
  } else 
   if(player==2 && this.hasWMP) { // WMP
      str ='<OBJECT ID="FSKOPlayer_'+this.conteneur+'" width='+this._width+' height='+this._height+'\n'
      +'classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95"\n'
      +'codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,0,02,902"\n'
      +'standby="Loading Microsoft Windows Media Player components..."\n'
      +'type="application/x-oleobject">\n'
      +'<PARAM NAME="FileName" VALUE="'+this._url+'">\n'
      +'<PARAM NAME="animationatStart" VALUE="true">\n'
      +'<PARAM NAME="transparentatStart" VALUE="true">\n'
      +'<PARAM NAME="autoStart" VALUE="'+this._autostart+'">\n'
      +'<PARAM NAME="showControls" VALUE="true">\n'
      +'<PARAM NAME="autoSize" VALUE="0">\n'
      +'<EMBED type="application/x-mplayer2"'
      +' pluginspage = "http://www.microsoft.com/Windows/MediaPlayer/"'
      +'SRC="'+this._url+'"'
      +'id="FSKOPlayer_'+this.conteneur+'" '
      +'width='+this._width+' height='+this._height+' AutoStart='+this._autostart+' autosize=0'
      +' transparentatStart=true animationatStart=true showControls=true>'
      +'</EMBED>\n'
      +'</OBJECT>';
      if (this.hasWMP == 2)
        this.ChangeURL = function(p_URL) {
          try {
          this._url = p_URL;
          eval('document.FSKOPlayer_'+this.conteneur+'.Filename = p_URL;');
        } catch(err) {};
        };
      else
        this.ChangeURL = function(p_URL) {
          this._url = p_URL;
          this.CreeLecteur();
        };
  } else 
  if(player==3 && this.hasReal) {
      // Real
      str +='<OBJECT ID="FSKOPlayer_'+this.conteneur+'"'
      +' CLASSID="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA"'
      +' WIDTH="'+this._width+'" HEIGHT="'+this._height+'">\n'
      +'<PARAM NAME="CONTROLS" VALUE="ControlPanel">\n'
      +'<PARAM NAME="CONSOLE" VALUE="Clip1">\n'
      +'<PARAM NAME="AUTOSTART" VALUE="'+this._autostart+'">\n'
      +'<PARAM NAME="nologo" value="true">'
      +'<PARAM NAME="NOJAVA" value="true">'
      +'<PARAM NAME="SRC" value="'+this._url+'">'
      +'<PARAM NAME="LOOP" value="'+this._loop+'">'
      +'<EMBED SRC="'+this._url+'" WIDTH='+this._width+' HEIGHT='+this._height
      +' type="audio/x-pn-realaudio-plugin"'
      +' NOLOGO=true NOJAVA=true CONTROLS=ControlPanel CONSOLE=Clip1'
      +' AUTOSTART='+this._autostart+' LOOP='+this._loop+'></EMBED>\n'
      +'</OBJECT>';
      if (this.hasReal == 2)
        this.ChangeURL = function(p_URL) {
          try {
          this._url = p_URL;
          eval('document.FSKOPlayer_'+this.conteneur+'.SetSource(p_URL);');
          } catch(err) {};
        };
      else
        this.ChangeURL = function(p_URL) {
          try {
          this._url = p_URL;
          this.CreeLecteur();
          } catch(err) {};
        };
} else {
      this.ChangeURL = function() {};
    }
  return str;
 };
 
 this.CreeLecteur = function() {
   var obj = document.getElementById(this.conteneur);
   var i=1;
   var str = '';
   while(str=='' && i < 4) str = this.makeSound(i);
   if (str == '' && obj) {
      if (this._url.lastIndexOf('/') > -1) 
        str = this._url.slice(this._url.lastIndexOf('/'));
      else str = this._url;
      str = '<a href="'+this._url+'" target="_blank"><b>'+str+'</b></a></br>';
      obj.innerHTML = str;
   }
   if (obj) 
   obj.innerHTML = str+this._creeLiens();
  else alert("Il n'y a pas de balise <DIV id='"+this.conteneur+"'></DIV> dans votre page");
  };
}

/*------------------------------------------------*
 * C'est ici que vous personnalisez votre lecteur
 *------------------------------------------------*/
var DreadIPlayer = new MultimediaPlayer(
  'DreadIPlayer',
  'http://dreadilicious.free.fr/Dread%20I%20Audio%20Files/Stronger_128kbps.mp3',
  'audio/mpeg');
// Insérez les paramètres de personalisation ici (hauteur, largeur ...)
/*DreadIPlayer.AjoutePiste('/lib/Z/Y/XXYZ/files/monfichier1.mp3', 'audio/mpeg', 'Titre de la piste 1');
/*DreadIPlayer.AjoutePiste('/lib/Z/Y/XXYZ/files/monfichier2.mp3', 'audio/mpeg', 'Titre de la piste 2');/
DreadIPlayer.CreeLecteur();
//-->
DreadIPlayer.AutoStart(false);