/**
 * Insertion d'un fichier Wmv
 * 28/05/2007 17:05:47
 * Version: Test
 *
 * Utilisation:
 * <script type=\"text/javascript\">
 * new insereWmv('clip_intro2.wmv', 'video_wmv_1', 300, 300, false, true, true, true).affiche();
 * </script>
 *
 *
 * Constructor: insereWmv
 *
 * Parameters:
 *  - String sVideo, le chemin vers la video
 *  - String sId, l'id de la vidéo 
 *  - Number nLargeur, la largeur de la vidéo
 *  - Number nHauteur, la hauteur de la vidéo
 *  - [Boolean bRepete], par defaut a true, repeter ou non la video (IE only)   
 *  - [Boolean bAfficheStatut], par defaut a true, afficher la barre de statut (IE only)  
 *  - [Boolean bAfficheControles], par defaut a true, afficher les controles (IE only)  
 *  - [Boolean bDemarrageAuto], par defaut a true, demarrer automtiquement la video (IE only)     
 */  
 
function insereWmv(sVideo, sId, nLargeur, nHauteur, bRepete, bAfficheStatut, bAfficheControles, bDemarrageAuto) {
	this.sVideo = sVideo;
	this.sId = sId;
	this.nLargeur = nLargeur;
	this.nHauteur = nHauteur; 
	this.bRepete = (bRepete == undefined) ? true : bRepete;
	this.bAfficheStatut = (bAfficheStatut == undefined) ? true : bAfficheStatut;
	this.bAfficheControles = (bAfficheControles == undefined) ? true : bAfficheControles;
	this.bDemarrageAuto = (bDemarrageAuto == undefined) ? true : bDemarrageAuto;
	this.sHtml = "";
	switch (this.renvoieNavigateur()) {
		case 'IE' :
			this.afficheIe();
			break;
		case 'GECKO' :
			this.afficheGecko();
			break;
		default :
			//
			break; 
	}
};
insereWmv.prototype.renvoieNavigateur = function() {
	var sNav = navigator.userAgent.toLowerCase();
	if(sNav.indexOf("msie") != -1) {
		return 'IE';
	} else if (sNav.indexOf("mozilla") != -1) {
		return 'GECKO'; 
	} else {
		return '';
	}
};
insereWmv.prototype.afficheIe = function() {
	this.sHtml += "<object id=\""+this.sId+"\" ";
	this.sHtml += "	codeBase=\"http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,0,02,902\" ";
	this.sHtml += "	type=\"application/x-oleobject\" ";
	this.sHtml += "	height=\""+this.nHauteur+"\" width=\""+this.nLargeur+"\" ";
	this.sHtml += "	standby=\"Chargement en cours...\" ";
	this.sHtml += "	classid=\"CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95\">\n";
	this.sHtml += "		<param name=\"filename\" value=\""+this.sVideo+"\" />\n";
	this.sHtml += "		<param name=\"showstatusbar\" value=\""+this.bAfficheStatut+"\" />\n";
	this.sHtml += "		<param name=\"showcontrols\" value=\""+this.bAfficheControles+"\" />\n";
	this.sHtml += "		<param name=\"autostart\" value=\""+this.bDemarrageAuto+"\" />\n";
	this.sHtml += "		<param name=\"loop\" value=\""+this.bRepete+"\" />\n";
	this.sHtml += "</object>";
};
insereWmv.prototype.afficheGecko = function() {
	this.sHtml += "<embed type=\"application/x-mplayer2\" ";
	this.sHtml += "	pluginspage=\"http://www.microsoft.com/Windows/MediaPlayer/\" ";
	this.sHtml += "	name=\"MediaPlayer\" src=\""+this.sVideo+"\" ";
	this.sHtml += "	autostart=\""+this.bDemarrageAuto+"\" ";
	this.sHtml += "	loop=\""+this.bRepete+"\" ";
	this.sHtml += "	showstatusbar=\""+this.bAfficheStatut+"\" ";
	this.sHtml += "	showcontrols=\""+this.bAfficheControles+"\" ";
	this.sHtml += "	height=\""+this.nHauteur+"\" width=\""+this.nLargeur+"\"";
	this.sHtml += "></embed>";
};
insereWmv.prototype.affiche = function() {
	document.write(this.sHtml);
};
insereWmv.prototype.afficheHtml = function(sIdCalque) {
	document.getElementById(sIdCalque).innerHTML = this.sHtml;
};

/**
 * Class: oPlugins
 *	Objet de détection des plugins
 */  
oPlugins = {
	/**
	 * Method: possedeWmp
	 *  Teste la présence de Windows Media Player sous Gecko
	 *  Si IE, renvoie true	  
	 *  
	 * Returns: 
	 *  Boolean, true si wmv supporté ou IE	 	 	 
	 */	 	 	
	possedeWmp: function() {
		if (navigator.plugins.toString() != undefined) {
			var aPlugins = [];
			aPlugins = navigator.plugins;
			for (var i = 0; i < aPlugins.length; i++) {
				if (aPlugins[i].name.indexOf('Media Player') != -1) 
					return true;
			}
		} else {
			// Sous Microsoft, un ativeX se charge de la détection
			return true;
		}
		return false;
	}
};
