// Flash Version Detector		v1.2.1
// documentation: http://www.dithered.com/javascript/flash_detect/index.html
// license: http://creativecommons.org/licenses/by/1.0/
// code by Chris Nott (chris[at]dithered[dot]com)
// with VBScript code from Alastair Hamilton (now somewhat modified)

function isDefined(property) {
		return (typeof property != 'undefined');
}

var flashVersion = 0;

function getFlashVersion() {
	var latestFlashVersion = 9;
	var agent = navigator.userAgent.toLowerCase();

		// NS3 needs flashVersion to be a local variable
		if (agent.indexOf("mozilla/3") != -1 && agent.indexOf("msie") == -1) {
			flashVersion = 0;
		 }

	// NS3+, Opera3+, IE5+ Mac (support plugin array):		check for Flash plugin in plugin array
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		var flashPlugin = navigator.plugins['Shockwave Flash'];
		if (typeof flashPlugin == 'object') {
			for (var i = latestFlashVersion; i >= 3; i--) {
			if (flashPlugin.description.indexOf(i + '.') != -1) {
					 flashVersion = i;
					 break;
			}
		 }
		}
	}

	// IE4+ Win32:		attempt to create an ActiveX object using VBScript
	else if (agent.indexOf("msie") != -1 && parseInt(navigator.appVersion) >= 4 && agent.indexOf("win")!=-1 && agent.indexOf("16bit")==-1) {
		var doc = '<scr' + 'ipt language="VBScript"\> \n';
		doc += 'On Error Resume Next \n';
		doc += 'Dim obFlash \n';
		doc += 'For i = ' + latestFlashVersion + ' To 3 Step -1 \n';
		doc += '		 Set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash." & i) \n';
		doc += '		 If IsObject(obFlash) Then \n';
		doc += '			flashVersion = i \n';
		doc += '			Exit For \n';
		doc += '		 End If \n';
		doc += 'Next \n';
		doc += '</scr' + 'ipt\> \n';
		document.write(doc);
	}

	// WebTV 2.5 supports flash 3
	else if (agent.indexOf("webtv/2.5") != -1) flashVersion = 3;

	// older WebTV supports flash 2
	else if (agent.indexOf("webtv") != -1) flashVersion = 2;

	// Can't detect in all other cases
	else {
		flashVersion = flashVersion_DONTKNOW;
	}

	return flashVersion;
}

flashVersion_DONTKNOW = -1;

/* Procédure d’écritures des différents éléments */
function genereCode() {
		if (debugMode == true) {
			var h= "<p style=\"color: red; border: 1px #ccc solid; padding: 1em;\">DEBUG:<br />Version flash : " + versionFlash +"<br />Variables : [" + variables + "]</p>";
			document.write(h);
		}
		/* OK :: génération du flash */
		if (versionFlash >= versionRequise) {
			var g = "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\"\n";
			g += "codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=" + versionRequise +",0,0,0\"\n";
			g += "width=\""+ L +"\" height=\""+ H + "\" align=\"" + align + "\">\n";
			g += "<param name=\"movie\" value=\"" + source + "\" />\n";
			g += "<param name=\"quality\" value=\"" + quality + "\" />\n";
			g += "<param name=\"scale\" value=\"" + scale + "\" />\n";
			g += "<param name=\"bgcolor\" value=\"" + bgCol + "\" />\n";
			g += "<param name=\"wmode\" value=\"" + transp + "\" />\n";
			g += "<param name=\"menu\" value=\"" + fMenu + "\" />\n";
			g += "<param name=\"salign\" value=\"" + source + "\" />\n";
			g += "<param name=\"flashvars\" value=\"" + variables + "\" />\n";
			g += "<embed src=\"" + source + "\" width=\"" + L + "\" height=\""+ H +"\" align=\"" + align + "\" quality=\"" + quality + "\" scale=\"" + scale + "\" bgcolor=\"" + bgCol + "\"";
			g += "wmode=\"" + transp + "\" flashvars=\"" + variables + "\" salign=\"" + salign + "\" menu=\"" + fMenu + "\" type=\"application/x-shockwave-flash\" pluginspage=\"" + urlMaj + "\" />\n";
			g += "</object>";
			document.write(g);
			}
		/* Flash installé mais nécessite une maj (ou élément alternatif)*/
		else if (versionFlash > 0) {document.write(htmlMaj);}
		/* Flash non-installé installation (ou élément alternatif) */
		else if (versionFlash == 0) {document.write(htmlNoflash);}
		/* Flash indétectable (ou élément alternatif) */
		else if (versionFlash == flashVersion_DONTKNOW || flashVersion == null) {
			document.write(htmlIndetect);
		}
}