/******************************************************************************************

Signature des fonctions

//Detect si la version et release du plugins et présente
bool function detect_flash()
bool function detect_flash(version, release)

//Ecrit un flash dans la page html
function write_flash(movie, width, height)
function write_flash_1(movie, width, height, quality, loop, play, menu)

//detect et insert le flash ou l'erreur
function insert_flash_1(movie, width, height)
function insert_flash_2(movie, width, height, langue)
function insert_flash_3(movie, width, height, version, release)
function insert_flash_4(movie, width, height, langue, version, release)
function insert_flash(movie, width, height, quality, loop, play, menu, langue, version, release)

//ecrit un bloc pour aller telecharger le plugin flash
write_erreur(langue);           (langue = 'fra' : 'eng')

la class css ".div-detection-flash" peut etre utiliser pour habiller le cadre de l'erreur lorsque que flash n'est pas present

*******************************************************************************************/
//  Parametre modifiable :
var imageGetFlash = '../img/commun/get_flash_player.gif';
var requiredVersion = 6;
var requiredRelease = 0;
var defaultLang = 'fra';



/***************************************************************************************/

//Debut script de détection

// System globals
var flash2Installed = false;    // boolean. true if flash 2 is installed
var flash3Installed = false;
var flash4Installed = false;
var flash5Installed = false; 
var flash6Installed = false; 
var flash7Installed = false;    
var flash8Installed = false;    
var flash9Installed = false;    
var maxVersion = 9;             // highest version we can actually detect
var actualVersion = 0;			// version the user really has  
var actualRelease = 0;
var jsVersion = 1.0;            // the version of javascript supported
var langue='fra';
var flashDescription='';
var isVersion2='';
var flashVersion;
var releaseTmp;

var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
jsVersion = 1.1;

// Write vbscript detection on ie win. IE on Windows doesn't support regular
// JavaScript plugins array detection.
if(isIE && isWin){
  document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
  document.write('on error resume next \n');
  document.write('flash2Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.2"))) \n');
  document.write('flash3Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.3"))) \n');
  document.write('flash4Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4"))) \n');
  document.write('flash5Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5"))) \n');  
  document.write('flash6Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6"))) \n');  
  document.write('flash7Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.7"))) \n');
  document.write('flash8Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.8"))) \n');
  document.write('flash9Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.9"))) \n');
  document.write('flash10Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash"))) \n');
  document.write('<\/SCR' + 'IPT\> \n'); // break up end tag so it doesn't end our script
}


function write_flash(movie, width, height){
	write_flash_1(movie, width, height, 'high', 'false', 'true', 'false');
}
function write_flash_1(movie, width, height, quality, loop, play, menu){

		moviename=movie.substring(0,movie.length-4);
		document.write( '<OBJECT  ID="'+moviename+'" CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'
		+ 'WIDTH="'+width+'" HEIGHT="'+height+'"'
		+ 'CODEBASE="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">'
		+ '<PARAM NAME="MOVIE" VALUE="'+movie+'" >'
		+ '<PARAM NAME="PLAY" VALUE="'+play+'" >'
		+ '<PARAM NAME="LOOP" VALUE="'+loop+'" >'
		+ '<PARAM NAME="QUALITY" VALUE="'+quality+'" >'
		+ '<PARAM NAME="MENU" VALUE="'+menu+'" >'
		+ '<EMBED NAME="'+moviename+'" ID="'+moviename+'" SRC="'+movie+'"'
		+ 'WIDTH="'+width+'" HEIGHT="'+height+'" '
		+ 'PLAY="'+play+'" '
		+ 'LOOP="'+loop+'" '
		+ 'QUALITY="'+quality+'" '
		+ 'MENU="'+menu+'" '
		+ 'TYPE="application/x-shockwave-flash" '
		+ 'PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">'
		+ '<\/EMBED>'
		+ '<\/OBJECT>' );

}
function write_erreur(langue) {

	//Message erreur Francais
	if (langue == "fra")
	{
		 document.write( '<div class="div-detection-flash"><span style="font-weight:normal;font-size: 11px;color: #000000;font-family: "Trebuchet MS", Arial, Helvetica, sans-serif; line-height: 14px;">');
			 
		 if (actualVersion==0)
			document.write('Vous ne disposez pas du plugin Flash pour visionner l\'animation.<br>Vous pouvez le t&eacute;l&eacute;charger gratuitement sur le site de ');
		 else
			document.write('Votre plugin Flash n\'est pas &agrave; jour pour visionner l\'animation.<br>Vous pouvez le mettre à jour gratuitement sur le site de ');
		 
		 document.write('<a href=\"http://www.macromedia.com/go/getflashplayer_fr" target=\"_blank\">Macromedia</a>.</span>');
		 document.write('<br><br><a href="http://www.macromedia.com/go/getflashplayer_fr" target="_blank"><img src="'+imageGetFlash+'" width="88" height="31" hspace="10" border="0" alt=""></a>');
		 
		 if (actualVersion!=0)
			document.write('<br><br><span align=\"center\" style=\"font-size: 9px;color: #000000;font-family:Trebuchet MS;\">Version plugin : '+flashDescription+'</span>');
		document.write('</div>\n');
	}
	//Message erreur Anglais
	if (langue=='eng')
	{
		document.write( '<div class="div-detection-flash"><span style="font-weight:normal;font-size: 11px;color: #000000;font-family: "Trebuchet MS", Arial, Helvetica, sans-serif; line-height: 14px;">');
			 
		 if (actualVersion==0)
			document.write('You do not have the plugin Flash to view the animation.<br>You can download it free on the site of');
		 else
			document.write('Your plugin Flash isn\'t up to date to view the animation.<br>You can update it free on the site of ');
		 
		 document.write('<a href=\"http://www.macromedia.com/go/getflash" target=\"_blank\">Macromedia</a>.</span>');
		 document.write('<br><br><a href="http://www.macromedia.com/go/getflash" target="_blank"><img src="'+imageGetFlash+'" width="88" height="31" hspace="10" border="0" alt=""></a>');
		 
		 if (actualVersion!=0)
			document.write('<br><br><span align=\"center\" style=\"font-size: 9px;color: #000000;font-family:Trebuchet MS;\">Plugin version : '+flashDescription+'</span>');
		
		document.write('</div>\n');
	}



}
function detect_flash(){
	return detect_flash_1(requiredVersion, requiredRelease);
}

function detect_flash_1(version, release){

  requiredVersion = version;
  requiredRelease = release;
  // If navigator.plugins exists...
  if (navigator.plugins) {
    // ...then check for flash 2 or flash 3+.
    if (navigator.plugins["Shockwave Flash 2.0"]
        || navigator.plugins["Shockwave Flash"]) {
      // Some version of Flash was found. Time to figure out which.
      
      // Set convenient references to flash 2 and the plugin description.
      isVersion2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
      flashDescription = navigator.plugins["Shockwave Flash" + isVersion2].description;

      flashVersion = parseInt(flashDescription.substring(16));
	  releaseTmp = flashDescription.split("r");
	  
	  actualRelease = parseInt(releaseTmp[releaseTmp.length-1]);

	  //alert("Flash plugin description: " + flashDescription );
      // We found the version, now set appropriate version flags. Make sure
      // to use >= on the highest version so we don't prevent future version
      // users from entering the site.
	  flash1Installed = flashVersion == 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;
    }
  }
  
  // Loop through all versions we're checking, and
  // set actualVersion to highest detected version.
  for (var i = 2; i <= maxVersion; i++) {  
    if (eval("flash" + i + "Installed") == true) actualVersion = i;
  }
   
 // DEBUG
 // alert("Version detected: " + actualVersion + "\nRelease detected: " + actualRelease +"\nLangue : "+langue);

  if (actualVersion > requiredVersion || (actualVersion == requiredVersion && actualRelease >= requiredRelease) )
	return true;
  else
	return false;

}

function get_version()
{
	detect_flash_1(0, 0);
	alert("Flash Version : "+actualVersion+"\nFlash Release : "+actualRelease);
}

function insert_flash_1(movie, width, height){
	insert_flash(movie, width, height, 'high','false', 'true', 'false', defaultLang, requiredVersion, requiredRelease);
}

function insert_flash_2(movie, width, height, langue){
	insert_flash(movie, width, height, 'high','false', 'true', 'false', langue, requiredVersion, requiredRelease);
}

function insert_flash_3(movie, width, height, version, release){
	insert_flash(movie, width, height, 'high', 'false', 'true', 'false', defaultLang, version, release);
}

function insert_flash_4(movie, width, height, langue, version, release){
	insert_flash(movie, width, height, 'high', 'false', 'true', 'false', langue, version, release);
}
function insert_flash(movie, width, height, quality, loop, play, menu, langue, version, release) {  
	if (detect_flash(version, release))
		write_flash(movie, width, height, quality, loop, play, menu);
	else
		write_erreur(langue);
}
