/////////////////////////////////////////////////////////////////////////////////////////////////////////
// Fonction : writeFlash
// Révision : 1.1 29.09.06
// Syntaxe : writeFlash(strFlash, myWidth, myHeight, flVersion)
// Variables :
// 		strFlash : le nom du Flash
//		myWidth : largeur en pixels
//		myHeight : hauteur en pixels
//		flVersion : indication de la version flash requise
//		myErr : le nom du fichier image de secours
// Retour : 
//		Si version correcte, le tag embed pour le Flash, si version incorrecte, un message de mise à jour
// Exemple d'usage:
//		writeFlash("monchemin/monfichierflash.swf", 400, 300, 7, "monchemin/monimage.jpg")
//		à l'endroit où le tag embed flash devrait être.			
/////////////////////////////////////////////////////////////////////////////////////////////////////////

// Init variables
var flash2Installed = false; var flash3Installed = false;
var flash4Installed = false; var flash5Installed = false;
var flash6Installed = false; var flash7Installed = false;
var flash8Installed = false; var flash9Installed = false;
var maxVersion   = 9;  // plus haute version existante
var actualVersion  = 0;  // version détectée
var hasRightVersion = false; // passe à true si version installée correspond 

var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false; // check IE
var isWin = (navigator.appVersion.indexOf("Windows") != -1) ? true : false; // Check Windows

// Si IE windows alors on utilise VBscript pour la détection activeX
if(isIE && isWin){
 document.write('<SCRIPT LANGUAGE=VBScript\> \n');
 document.write('on error resume next \n');
 document.write('flash2Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.2"))) \n');
 document.write('on error resume next \n');
 document.write('flash3Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.3"))) \n');
 document.write('on error resume next \n');
 document.write('flash4Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4"))) \n');
 document.write('on error resume next \n');
 document.write('flash5Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5"))) \n'); 
 document.write('on error resume next \n');
 document.write('flash6Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6"))) \n');
 document.write('on error resume next \n');
 document.write('flash7Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.7"))) \n'); 
 document.write('on error resume next \n');
 document.write('flash8Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.8"))) \n'); 
 document.write('on error resume next \n');
 document.write('flash9Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.9"))) \n'); 
 document.write('</SCRIPT\> \n');
}

// Détection 
function detectFlash(flV) { 
	 if (navigator.plugins) {
	  if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
	   var isVersion2    = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
	   var flashDescription  = navigator.plugins["Shockwave Flash" + isVersion2].description;
	   // alert("Flash décrit: " + flashDescription);
	   var flashVersion   = parseInt(flashDescription.charAt(flashDescription.indexOf(".") - 1));
	   flash2Installed   = flashVersion == 2;   
	   flash3Installed   = flashVersion == 3;
	   flash4Installed   = flashVersion == 4;
	   flash5Installed   = flashVersion == 5;
	   flash6Installed   = flashVersion == 6;
	   flash7Installed   = flashVersion == 7;
	   flash8Installed   = flashVersion == 8;
	   flash9Installed   = flashVersion >= 9;	
	  }
	}
	for (var i = 2; i <= maxVersion; i++) { 
	  if (eval("flash" + i + "Installed") == true) actualVersion = i;
	}
	if(navigator.userAgent.indexOf("WebTV") != -1) actualVersion = 3;
	//  alert("version detectée: " + actualVersion);
	if (actualVersion >= flV) {
	  hasRightVersion = true;               
	} 
	else { 
	  hasRightVersion = false;
	 }
} 

// fonction d'appel
function writeFlash(strFlash, myWidth, myHeight, flVersion, myErr) {
	var posVersion = strFlash.search(/#version=.+/);
	if(posVersion != -1) {
		var objectTagVersion =
		strFlash.substring(posVersion+9,posVersion+10);
	 	if (objectTagVersion != flVersion) {
	 		flVersion = objectTagVersion;
	 	}
	}

	// appel de la détection (cf ci dessus)
	detectFlash(flVersion);

	if(hasRightVersion) {
	// si version flash correcte
	   var oeTags = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'
			+ 'width="'+myWidth+'" height="'+myHeight+'"'
			+ 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">'
			+ '<param name="movie" value="'+strFlash+'" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /> <param name="wmode" value="transparent" />'
			+ '<embed  wmode="transparent" src="'+strFlash+'" quality="high" bgcolor="#ffffff" '
			+ 'width="'+myWidth+'" height="'+myHeight+'" name="'+strFlash+'" align="middle"'
			+ 'play="true"'
			+ 'loop="false"'
			+ 'quality="high"'
			+ 'allowScriptAccess="sameDomain"'
			+ 'type="application/x-shockwave-flash"'
			+ 'pluginspage="http://www.macromedia.com/go/getflashplayer">'
			+ '<\/embed>'
			+ '<\/object>';
			document.write(oeTags);   // intégrer le clip Flash
	
	}
	else {
	  // Si version flash incorrecte
		var oeTags = '<a href="http://www.macromedia.com/go/getflash/" target="_blank" ><img src="'+myErr+'" style="float:left" border="0"></a>';
			document.write(oeTags);  // Insérer contenu non-Flash 

			
			

	} 
}