// test navigateur
function isMozilla()
{    
if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) 
	return(true);
return(false);	
}

// -------------------------------------------------------------
// creer la fenetre player vlc différemment selon IE ou Moz
function genere_code_appel_vlc(largeur, hauteur, flux)    
{
var html='';	
var vlc_ff_obj = null;
var vlc_ie_obj = null;
        
if(isMozilla())
	{
	// declaration de l'embed
    html = genere_code_appel_vlc_embed(largeur, hauteur, flux);    
    document.write(html);
    
    // recup de l'objet et init
    vlc_ff_obj = document.getElementById("vlc_ff");
    initialiser_embed_vlc(vlc_ff_obj, flux);
	}
        
				
else {
       // IE
       //alert("IE");
        html = genere_code_appel_vlc_ActiveX(largeur, hauteur, flux)   ;
	    document.write(html);
        
        // recup de l'objet et init
        vlc_ie_obj = document.getElementById("vlc_ie");
        initialiser_ActiveX_vlc(vlc_ie_obj, flux);
    }
}    

// -------------------------------------------------------------
// code de création de la fenetre player vlc dans un environnement Moz
// (balise embed)
function genere_code_appel_vlc_embed(largeur, hauteur, flux)    
{
var html = "";	
html +='<embed type="application/x-vlc-plugin" pluginspage="http://www.videolan.org" version="VideoLAN.VLCPlugin.2" width="' + largeur + '" height="' + hauteur + '" target="" autoplay="no" loop="no" id="vlc_ff"></embed>';

return(html);
}

// -------------------------------------------------------------
// code de création de la fenetre player vlc dans un environnement IE
// (balise OBJECT -> ActiveX)
function genere_code_appel_vlc_ActiveX(largeur, hauteur, flux)    
{
var	html = "";	
html +='<OBJECT classid="clsid:E23FE9C6-778E-49D4-B537-38FCDE4887D8"';
html +='codebase="http://downloads.videolan.org/pub/videolan/vlc/latest/win32/axvlc.cab"';
html +='width="' + largeur + '" height="' + hauteur + '" id="vlc_ie" events="True">';
html +='<param name="Src" value="">';
html +='<param name="ShowDisplay" value="True">';
html +='<param name="AutoLoop" value="False">';
html +='<param name="AutoPlay" value="False">';
html +='<param name="Volume" value="100">';
html +='</OBJECT>';
// iframe sinon clic sur object --> tout blanc
// html +='<iframe frameborder="0"></iframe>';	
return(html);        
}	

// -------------------------------------------------------------
// Initialisation de l'embed VLC
// Volume et désentrelacement
function initialiser_embed_vlc(vlc_ff_obj, flux)
{
if(!vlc_ff_obj)
	return;
// test version
if ( typeof(vlc_ff_obj) != 'undefined' && typeof(vlc_ff_obj.playlist) != 'undefined' )
	{
           // plugin vlc >= 0.8.6
            //alert("VLC >= 0.8.6");
            vlc_ff_obj.playlist.items.clear();
            vlc_ff_obj.playlist.add(flux,"",":vout-filter=deinterlace :deinterlace-mode=linear");
            vlc_ff_obj.audio.volume=100;
            vlc_ff_obj.playlist.play();
            // autres methodes
            // vlc_ff_obj.playlist.play();
            // vlc_ff_obj.playlist.togglePause();
            // vlc_ff_obj.playlist.stop();
            // vlc_ff_obj.audio.toggleMute();
            // vlc_ff_obj.video.toggleFullscreen();
            
        } 
else 
	if ( typeof(vlc_ff_obj) != 'undefined' && typeof(vlc_ff_obj.clear_playlist) != 'undefined' )
		{
            // plugin vlc <= 0.8.5 (pas de deinterlace)
            //alert("VLC <= 0.8.5");
            vlc_ff_obj.clear_playlist();
            vlc_ff_obj.add_item(flux);
            vlc_ff_obj.set_volume(100);
            vlc_ff_obj.play();
            // autres methodes
            // vlc_ff_obj.play();
            // vlc_ff_obj.pause();
            // vlc_ff_obj.stop();
            // vlc_ff_obj.mute();
            // vlc_ff_obj.fullscreen();
            
		}
	
}

// ----------------------------------------------------------
// Initialisation de l'ActiveX VLC
// Volume et désentrelacement
function initialiser_ActiveX_vlc(vlc_ie_obj, flux)
{
if(!vlc_ie_obj)
	return;
	
        // options deinterlace - ajout playlist - play
        vlc_ie_obj.playlistClear();
        var options=[":vout-filter=deinterlace"][":deinterlace-mode=linear"];
        vlc_ie_obj.addTarget(flux,options,2,0);
        vlc_ie_obj.play();
        // autres methodes
        // vlc_ie_obj.play();
        // vlc_ie_obj.pause();
        // vlc_ie_obj.stop();
        // vlc_ie_obj.toggleMute();
        // vlc_ie_obj.fullscreen();
}


function genere_code_appel_wmp(largeur, hauteur, url)
{
var html = "";
var video_player;

video_player = new ADDEO_PLAYER("player_wmp", url, "wmv");
video_player.setAttribute('width', largeur);
video_player.setAttribute('height', hauteur);
video_player.addParam('ShowControls', 'true');
video_player.addParam('ShowTracker', 'true');
video_player.addParam('AutoStart', 'true');
	
html = video_player.generer_html();

//alert(html);
document.write(html);
//return(html);

}


// ------------------------------------------------------
// Constructeur
function ADDEO_PLAYER(nom_player, fichier, type_fichier)
{
	this.nom = nom_player;			// nom de 'l'object' du DOM
	this.object = null;					// 'Object' Active X ou plug-in
	this.layer = null;					// layer hÚbergeant cet objet (optionnel)
	this.couleur_fond = "";

	this.isOpen = false;		
	this.isPlaying = false;
	this.duree = 0;
	this.fps = 0;						// frames per second
	this.courante = 0;		
	this.periode = 200;					// delta d'exec de tout appel par 'setInterval'
	this.etat_lecture= 0;				//0 = stop; 1=pause; 2=lecture
	this.etat_mute= 0;						//0 = du son; 1 = muted
	this.timerID = 0;
	this.etat=-1;

	this.fin_atteinte=0;
	
	// ET 21/09/2006 
	this.type_player="";
	if (typeof (window.ActiveXObject) != 'undefined')
	{
		this.true_value="true";
		this.false_value="false";
		this.activex=1;
	}
	else
	{
		this.true_value="1";
		this.false_value="0";
		this.activex=0;
	}

	// ET 21/09/2006 
	//this.WMP_version="6.4";
	this.WMP_version="10";


	// ET 01/08/2006
	// ajout pour pouvoir customiser l'objet
	this.params = new Object();
	this.variables = new Object();
	this.attributes = new Array();
	
	// ET 27/09/2006 param de personnalisation
	this.parametres=null;

	//------------------------------------------------
	this.setAttribute=function(name, value)
	{
		this.attributes[name] = value;
	};
	
	//------------------------------------------------
	this.getAttribute= function(name)
	{
		return this.attributes[name];
	};

	//------------------------------------------------
	this.addParam= function(name, value)
	{
		this.params[name] = value;
	};

	//------------------------------------------------
	this.getParams= function()
	{
		return this.params;
	};

	//------------------------------------------------
	this.addVariable= function(name, value)
	{
		this.variables[name] = value;
	};

	//------------------------------------------------
	this.getVariable= function(name)
	{
		return this.variables[name];
	};

	//------------------------------------------------
	this.getVariables= function()
	{
		return this.variables;
	};

	// -------------------------------------------------------------
	this.type_definir= function (fichier_type)
	{
		var mimeTypes = new Array();
		var i;
	

		var IE_mimetype = 'application/x-oleobject';

		if (typeof (window.ActiveXObject) != 'undefined')// || typeof(window.GeckoActiveXObject) != 'undefined') 
		{
		    return IE_mimetype;
		} 
		
		if (!fichier_type)	  return('application/x-mplayer2');

		mimeTypes['midi'] = ['application/x-oleobject','video/quicktime', 'audio/midi', 'audio/x-midi',  'application/x-mplayer2'];
		mimeTypes['wav'] = ['application/x-oleobject', 'video/quicktime', 'audio/wav', 'audio/x-wav',  'application/x-mplayer2'];
		mimeTypes['mp3'] = ['audio/mpeg', 'audio/x-mpeg', 'audio/mp3', 'audio/x-mp3', 'audio/mpeg3', 'audio/x-mpeg3', 'audio/mpg', 'audio/x-mpg', 'audio/x-mpegaudio', 'application/x-mplayer2'];
		mimeTypes['wmv'] = ['video/x-ms-wmv', 'application/x-mplayer2'];


		if (typeof navigator.mimeTypes != 'undefined' && navigator.mimeTypes.length > 0) 
		{
		    var mime = navigator.mimeTypes;
		    var mime_type=mimeTypes[fichier_type];
		    if (typeof(mime_type)!='undefined')
		    { 
				for (i = 0; i < mime_type.length; i++) 
				{
					if (typeof mime[mime_type[i]] != 'undefined') 
					{
						return (mime_type[i]);
					}
				}
			}
		}
	  return('application/x-mplayer2');
	};

	//init par defaut
	this.setAttribute('src', fichier); 
	this.setAttribute('width', '100%');
	this.setAttribute('height', '100%');
	this.setAttribute('id', nom_player);
	this.setAttribute('name', nom_player);
	this.setAttribute('type_ns', this.type_definir(type_fichier));
	this.setAttribute('type_ie', 'application/x-oleobject');
	this.setAttribute('pluginspage',	'http://microsoft.com/windows/mediaplayer/en/download');

	if (this.WMP_version=="10")
	{
		// player 7 Ó 10	pose pb ??
		this.setAttribute('classid', 'clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6');
	}
	else
	{
		// player 6.4	
		this.setAttribute('classid', 'clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95');
	}
	this.setAttribute('codebase', 'http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#version=Version=5,1,52,701');
	
	
	this.addParam('AutoStart', this.false_value);

	if (this.WMP_version=="10" && this.activex)
	{
		// attributs supportÚs : autoStart,balance,baseURL,captioningID,currentPosition,currentMarker,
		//defaultFrame,enableContextMenu,enabled,fullScreen,invokeURLs,mute,playCount,rate,
		//SAMIFileName,SAMILang,SAMIStyle,stretchToFit,uiMode,URL,volume,windowlessVideo 
		
		this.addParam('uiMode', "full"); //invisible, none, mini, full
		this.addParam('stretchToFit', this.true_value);
		//this.addParam('windowlessVideo', this.true_value);
	}
	else
	{
		this.addParam('ShowStatusBar', this.false_value);
		this.addParam('ShowControls', this.false_value);
		this.addParam('ShowTracker', this.false_value);
		this.addParam('ShowPositionControls', this.false_value);
		this.addParam('EnableContextMenu', this.false_value);
		this.addParam('AutoSize', '-1');
		this.addParam('DisplaySize', '4');
	}
	
		this.addParam('AutoRewind', this.false_value);
	



	// -------------------------------------------------------------
	// Code html de l'objet
	this.generer_html= function ()
	{
		var html="";

		
		var params = this.getParams();
		var cle;
		
		// ns
		if (isMozilla()) 
		{ 
			html += '<embed '; 
			html += ' type="'+ this.getAttribute('type_ns') +'" ';
			html += ' pluginspage="'+ this.getAttribute('pluginspage') +'" ';
			html += ' src="'+ this.getAttribute('src') + '"'; 
			html += ' width="'+ this.getAttribute('width') + '"';
			html += ' height="'+ this.getAttribute('height') +'"';
			html += ' id="'+ this.getAttribute('id') +'" ';
			html += ' name="'+ this.getAttribute('id') +'" ';
		
			 for(cle in params)
			{ 
				html += [cle] +'="'+ params[cle] +'" '; 
			}

			html += '/>';
		}
		else //ie
		{
			html += '<object '; 
			html += ' classid="'+ this.getAttribute('classid') +'" ';
			html += ' type="'+ this.getAttribute('type_ie') +'" ';
			html += ' codebase="'+ this.getAttribute('codebase') +'" ';
			html += ' width="'+ this.getAttribute('width') + '"';
			html += ' height="'+ this.getAttribute('height') +'"';
			html += ' id="'+ this.getAttribute('id') +'" ';
			//html += ' name="'+ this.getAttribute('id') +'" ';
			html += ' data="'+ this.getAttribute('src') +'" ';
			html += '>';

			if (this.WMP_version=="10")
				html += '<param name="url" value="'+ this.getAttribute('src') +'" />'; 
			else
				html += '<param name="FileName" value="'+ this.getAttribute('src') +'" />'; 


			 for(cle in params)
			{ 
				html += '<param name="'+ cle +'" value="'+ params[cle] +'" />'; 
			}
			html += "Veuillez patienter pendant le chargement de la video...</object> ";
		}
		//alert(html);
		return(html);
	};
	
	

	// ----------------------------------------------
	// Pour charger la video dans le player; 
	this.charger = function (fichier)
	{
		var player;
		var nom_player;

		player = ADDEO_PLAYER_adresse(this);
		if(player)
			{
			this.setAttribute('src', fichier); 
			this.isOpen = false;
			this.isPlaying = false;
			if (this.WMP_version=="10")
			{
				player.url=fichier;
			}
			else
				player.FileName=fichier;
			this.courante = 0;
			}
	};

	
	//---------------------
	this.definir_volume = function (pourcent)
	{
		var o = ADDEO_PLAYER_adresse(this) ;
		if(o)
		{
			var vol =  -1000 + pourcent *10; // -10000 == 0, 0 == Ó fond

			if(typeof(o.Volume) != "undefined")
				o.Volume = vol;
			else if(typeof(o.SetVolume) != "undefined")
					o.SetVolume(vol);
		}
	};
	
}

function ADDEO_PLAYER_adresse(P) 
{
	var id_objet; 
	
	if(P.object)
		return(P.object);

	id_objet=P.nom;
	
	if (document.getElementById) 
	{
		P.object=document.getElementById(id_objet);
		return(P.object);
	}
	if(document.all) 
	{
		P.object=document.all(id_objet);
		return(P.object);
	}
		
	if(document.layers)	
	{
		P.object=document.layers(id_objet);
		return(P.object);
	}

    
return(null);
}
		






