// Flash Player & Browser Detection
// Nathan McKinley

// 13-01-05 Added Firefox support
// 26-05-04 Renewed Browser detection to extent to more browsers and to include browser minor version numbers
// 09-03-04 Added JS detect
// 03-02-04 Updated
// 27-01-04 Created

// Set the required Flash player version
var requiredFlash = 6;


//STRING CHECKER
//===============================================
function findString(string)
{
	place = agent.indexOf(string) + 1;
	thestring = string;
	return place;
}

//===============================================
function checkCompatibility()
{

//=====================================
//BROWSER

	agent = navigator.userAgent.toLowerCase();
	var reportedName = navigator.appName;

	var OS, browser, version, total, fullVersion;
	var browserCompatible = false;

	if (findString('konqueror'))
	{
		browser = "Konqueror";
		OS = "Linux";
	}
	else if (findString('safari')) browser = "Safari";
	else if (findString('omniweb')) browser = "OmniWeb"
	else if (findString('opera')) browser = "Opera"
	else if (findString('webtv')) browser = "WebTV";
	else if (findString('icab')) browser = "iCab"
	else if (findString('msie')) browser = "Internet Explorer";
	else if (findString('netscape')) browser = "Netscape"
	else if (findString('firefox')) browser = "Firefox"
	else if (!findString('compatible'))
	{
		browser = "Netscape Navigator"
		version = agent.charAt(8);
	}
	else browser = "An unknown browser";

	if (!version) version = agent.charAt(place + thestring.length);

	// Interrogate further for minor version number
	if (browser == "Internet Explorer")
	{
		fullVersion = parseFloat(agent.substr(agent.indexOf("msie ")+5, 3));
		if (fullVersion>5) browserCompatible = true;
	}
	else if (browser == "Netscape")
	{
		fullVersion = parseFloat(agent.substr(agent.indexOf("netscape/")+9, 4));
		if (fullVersion>7) browserCompatible = true;
	}
	else if (browser == "Netscape Navigator")
	{
		if (version == 4)  fullVersion = parseFloat(agent.substr(agent.indexOf("mozilla/")+8, 4));
		else if (agent.indexOf("gecko")) fullVersion = parseFloat(agent.substr(agent.lastIndexOf("/")+1, 4))
		if (fullVersion>4.7) browserCompatible = true;
	}
	else if (browser == "Opera")
	{
		if (findString("opera/")) fullVersion = parseFloat(agent.substr(agent.indexOf("opera/")+ 6, 4));
		else if (findString("opera ")) fullVersion = parseFloat(agent.substr(agent.indexOf("opera ")+ 6, 4));
		if (fullVersion>7) browserCompatible = true;
	}
	else if (browser == "Firefox")
	{
		fullVersion = parseFloat(agent.substr(agent.indexOf("firefox/")+8, 4));
		if (fullVersion>0.9) browserCompatible = true;
	}
	else fullVersion = version;

	if (!OS)
	{
		if (findString('linux')) OS = "Linux";
		else if (findString('x11')) OS = "Unix";
		else if (findString('mac')) OS = "Mac"
		else if (findString('win')) OS = "Windows"
		else OS = "an unknown operating system";
	}

//END BROWSER DETECT
//=====================================
	

//=====================================
//FLASH

	// NS3 needs flashVersion to be a local variable
	// IE creates the variable through the VBScript Shockwave Object
	if ( (browser == "Netscape Navigator" || browser == "Netscape") && version == 3 )
	{
		flashVersion = 0;
	}
	
	// NS3+, Opera3+, IE5+ Mac, Firefox (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 (flashPlugin == undefined)
		{
			flashVersion = 0;
		}
		else if (typeof flashPlugin == 'object')
		{
			if (flashPlugin.description.indexOf('7.') != -1) flashVersion = 7;
			else if (flashPlugin.description.indexOf('6.') != -1) flashVersion = 6;
			else if (flashPlugin.description.indexOf('5.') != -1) flashVersion = 5;
			else if (flashPlugin.description.indexOf('4.') != -1) flashVersion = 4;
			else if (flashPlugin.description.indexOf('3.') != -1) flashVersion = 3;
		}
	}

	// IE4+ Win32:  attempt to create an ActiveX object using VBScript
	else if (browser ==  "Internet Explorer" && version >= 4 && OS == "Windows" && agent.indexOf("16bit")==-1 )
	{
		document.write('<scr' + 'ipt language="VBScript"\> \n');
		document.write('on error resume next \n');
		document.write('dim obFlash \n');
		document.write('set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.7") \n');
		document.write('if IsObject(obFlash) then \n');
		document.write('flashVersion = 7 \n');
		document.write('else set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.6") end if \n');
		document.write('if flashVersion < 7 and IsObject(obFlash) then \n');
		document.write('flashVersion = 6 \n');
		document.write('else set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.5") end if \n');
		document.write('if flashVersion < 6 and IsObject(obFlash) then \n');
		document.write('flashVersion = 5 \n');
		document.write('else set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.4") end if \n');
		document.write('if flashVersion < 5 and IsObject(obFlash) then \n');
		document.write('flashVersion = 4 \n');
		document.write('else set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.3") end if \n');
		document.write('if flashVersion < 4 and IsObject(obFlash) then \n');
		document.write('flashVersion = 3 \n');
		document.write('end if');
		document.write('</scr' + 'ipt\> \n');
	}

	// WebTV 2.5 supports flash 3
	else if (agent.indexOf("webtv/2.5") != -1) flashVersion = 3;

	// older WebTV supports flash 2
	else if (browser == "WebTV") flashVersion = 2;

// END FLASH DETECT
//=====================================
	
	var flashCanPlay = (flashVersion >= requiredFlash);
	
	if (flashCanPlay && browserCompatible)
	{
		return true;
	}
	else
	{
		return false;
	}
}
