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,EmbedFlashVars) {
	var widths = width.split(";");
	var heights = height.split(";");
	
	var width_flash = widths[0];
	var height_flash = heights[0];

	var width_img = widths[widths.length -1];
	var height_img = heights[heights.length -1];
	
	if(hasRightVersion) {
		var flashTags = '<object style="display:" data="'+src+'" '  + 'width="'+width_flash+'" height="'+height_flash+'"'
		+ ' name="Flash_'+id+'" id="Flash_'+id+'"'
		+ 'type="application/x-shockwave-flash">'
		+ '<param name="movie" value="'+src+'">'
		+ FlashVars
		+ '<param name="play" value="true">'
		+ '<param name="LOOP" value="true">'
		+ '<param name="quality" value="high">'
		+ '<param name="menu" value="false">'
		+ '<param name="wmode" value="transparent">';

		if (EmbedFlashVars!=undefined) {
		flashTags += '<embed src="'+src+'" width="'+width_flash+'" height="'+height_flash+'" quality="high" '
			+ 'type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" swliveconnect="true" '
			+ 'flashvars="'+EmbedFlashVars+'" >'
			+ '</embed>';
		}
		flashTags += '</object>'
		+ '<img style="display:none" border="0"  id="Image_'+id+'" src="'+alternateImg+'" height="'+height_img+'" width="'+width_img+'" alt="'+alt+'">';
		//alert(flashTags);
		document.write(flashTags);
  	} else {  
		var alternateContent = '<img  border="0"  src="'+alternateImg+'" height="'+height_img+'" width="'+width_img+'" 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 style_play="display:;";
			var style_stop="display:;";
		}

		if(optionDisplay == 1) {
			var style_play="display:none;";
			var style_stop="display:;";
		}

		if(optionDisplay == 2) {
			var style_play="display:none;";
			var style_stop="display:none;";
		}

		var commandeTags = 	'<img onClick="boutonPlay(\''+id+'\',\''+optionDisplay+'\');" border="0"  id="Play_'+id+'"  src="'+src+'"  alt="'+altPlay+'" style="'+style_play+'">'
		+'<img onClick="boutonStop(\''+id+'\',\''+optionDisplay+'\');" id="Stop_'+id+'" border="0"  src="'+srcStop+'" alt="'+altStop+'" style="'+style_stop+'">';

		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 = '';
		 
	};
	if(optionDisplay == 2){
		 document.getElementById("Play_"+id).style.display = 'none';
	}
}


// 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';

	}
	if(optionDisplay == 2){
		 document.getElementById("Stop_"+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()
{
	 //alert("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();
	 }
}

