var requiredVersion = 7;
var useRedirect = false;
var useAlternate = true;
var noFlashPage = "http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";
var upgradePage = "http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";

var flash2Installed = false;
var flash3Installed = false;
var flash4Installed = false;
var flash5Installed = false;
var flash6Installed = false;
var flash7Installed = false;
var maxVersion = 7;
var actualVersion = 0;
var hasRightVersion = true;
var jsVersion = 1.0;

var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.indexOf("Windows") != -1) ? true : false;

jsVersion = 1.1;

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('</SCR' + 'IPT\> \n');
}

function detectFlash() {  
  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;
      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;
    }
  }

  for (var i = 2; i <= maxVersion; i++) {  
    if (eval("flash" + i + "Installed") == true) {
	actualVersion = i;	
    }
  }
  if(navigator.userAgent.indexOf("WebTV") != -1) actualVersion = 3;  
  if (actualVersion >= requiredVersion) {
    if (useRedirect) {
      if(jsVersion > 1.0) {
      } else {
      }
    }
    hasRightVersion = true;                
  } else {  
    if (useRedirect) {
      if(jsVersion > 1.0) {
        window.location.replace((actualVersion >= 2) ? upgradePage : noFlashPage);
      } else {
        window.location = (actualVersion >= 2) ? upgradePage : noFlashPage;
      }
    }
	else if (useAlternate) {
		hasRightVersion = false;
	}
  }
  //alert('flashVersion= '+flashVersion);
}

detectFlash();



function injecteFlash(id,src, alternateImg, width, height,alt,FlashVars) {
  	if(hasRightVersion) { 
   	 var flashTags = '<object style="display:" data="'+src+'" ' 
   	 + 'width="'+width+'" height="'+height+'"'
	 + ' name="Flash_'+id+'" id="Flash_'+id+'"'
   	 + 'type="application/x-shockwave-flash">'
   	 + '<param name="movie" value="'+src+'">'
	 + FlashVars
   	 + '<param name="play" value="true">'   	
   	 + '<param name="quality" value="high">'
   	 + '<param name="menu" value="false">'
	 + '<param name="wmode" value="transparent">'
   	 + '</object>'
	 + '<img style="display:none" border="0"  id="Image_'+id+'" src="'+alternateImg+'" height="'+height+'" width="'+width+'" alt="'+alt+'">';
	 //alert(FlashVars);
	 document.write(flashTags);
  } else {  
   	 var alternateContent = '<img  border="0"  src="'+alternateImg+'" height="'+height+'" width="'+width+'" alt="'+alt+'">';
   	 document.write(alternateContent);
  	}
}



// optionDisplay 0 toujours visible, 1 cache 
function injecteCommandeFlash(id, src, altPlay, altStop,optionDisplay) {
  	if(hasRightVersion) { 
	 var srcStop = src.replace(/(_play\.)/, "_stop.");
	 if(optionDisplay == 0)
		 var commandeTags = 	'<img onClick="boutonPlay(\''+id+'\',\''+optionDisplay+'\');" border="0"  id="Play_'+id+'"  src="'+src+'"  alt="'+altPlay+'" style="display:">'
		 +'<img onClick="boutonStop(\''+id+'\',\''+optionDisplay+'\');" id="Stop_'+id+'" border="0"  src="'+srcStop+'" alt="'+altStop+'" style="display:">';
	 else
		 var commandeTags = 	'<img onClick="boutonPlay(\''+id+'\',\''+optionDisplay+'\');" border="0"  id="Play_'+id+'"  src="'+src+'" alt="'+altPlay+'" style="display:none">'
		 +'<img  onClick="boutonStop(\''+id+'\',\''+optionDisplay+'\');" border="0" id="Stop_'+id+'"  src="'+srcStop+'"  alt="'+altStop+'" style="display:">';
	 document.write(commandeTags);
  }
}

// optionDisplay 0 toujours visible, 1 cache 
function boutonPlay(id,optionDisplay){
        
	if(optionDisplay == 1){
		 document.getElementById("Play_"+id).style.display = 'none';
		 document.getElementById("Image_"+id).style.display = 'none';
		 document.getElementById("Stop_"+id).style.display = '';
		 document.getElementById("Flash_"+id).style.display = '';
	}else{
		 document.getElementById("Image_"+id).style.display = 'none';
		 document.getElementById("Flash_"+id).style.display = '';
		 
	}
}


// optionDisplay 0 toujours visible, 1 cache 
function boutonStop(id,optionDisplay){
	if(optionDisplay == 1){
		 document.getElementById("Play_"+id).style.display = '';
		 document.getElementById("Image_"+id).style.display = '';
		 document.getElementById("Stop_"+id).style.display = 'none';
		 document.getElementById("Flash_"+id).style.display = 'none';
	}else{
		 document.getElementById("Image_"+id).style.display = '';
		 document.getElementById("Flash_"+id).style.display = 'none';

	}
}


function injecteCommandeAllFlash(src, altPlay, altStop) {
  	if(hasRightVersion) { 
	 var srcStop = src.replace(/(_play.)/, "_stop.");
	 var commandeTags = 	'<img onClick="boutonPlayAll();" border="0"   src="'+src+'"  alt="'+altPlay+'" style="display:">'
				      +'<img onClick="boutonStopAll();" border="0"  src="'+srcStop+'" alt="'+altStop+'" style="display:">';
	 
	 document.write(commandeTags);
  }
}


function boutonPlayAll(){
        
	 var imgs = document.getElementsByTagName("img");
	 for (var i=0; i < imgs.length; i++){
		 if ( imgs[i].getAttribute("id") != null)
			if ( imgs[i].getAttribute("id").search(/^Play_./) != -1)
				 imgs[i].onclick(); 
	 }
}

function boutonStopAll(){
        
	 var imgs = document.getElementsByTagName("img");
	 for (var i=0; i < imgs.length; i++){
		 if ( imgs[i].getAttribute("id") != null)
			 if ( imgs[i].getAttribute("id").search(/^Stop_./) != -1)
				 imgs[i].onclick();
	 }
}

