// Flash Detection / Redirect (cookie variant)  v1.0
// http://www.dithered.com/javascript/flash_cookie/index.html
// code by Chris Nott (chris@dithered.com)

var dontKnow = false;
var flashVersion = 0;

function flashDetect() {	
	var agent = navigator.userAgent.toLowerCase(); 
	
	// IE4+ on Win32:  attempt to create an ActiveX object using VBScript
	if (agent.indexOf("msie") != -1 && parseInt(navigator.appVersion) >= 4 && agent.indexOf("win")!=-1 && agent.indexOf("16bit")==-1) {
		document.write('<scr' + 'ipt language="VBScript"\> \n');
		document.write('on error resume next \n');
		document.write('if IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6")) then flashVersion = 6 \n');
		document.write('if flashVersionn < 6 and IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5")) then flashVersion = 5 \n');
		document.write('if flashVersion < 5 and IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4")) then flashVersion = 4 \n');
		document.write('if flashVersion < 4 and IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.3")) then flashVersion = 3 \n');	
		document.write('</scr' + 'ipt\> \n'); 
	}
	
	// NS3+ and Opera3+ (support plugin array):  check for Flash plugin in plugin array
	else if (navigator.plugins != null && navigator.plugins.length > 0) {
		var flashPlugin = navigator.plugins['Shockwave Flash'];
		if (typeof flashPlugin == 'object') { 
			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;
		}
	}
	
	// WebTV 2.5 supports flash 3
	else if (agent.indexOf("webtv/2.5") != -1) flashVersion = 3;
	
	// Can't detect in all other cases
	else flashVersion = 'dontKnow';
	
	return flashVersion;
}


// Retrieve flash cookie
var cookieStart = document.cookie.indexOf('flash');
if (cookieStart != -1) {
	var cookieEnd = document.cookie.indexOf(';', cookieStart);
	if (cookieEnd == -1) cookieEnd = document.cookie.length;
	flashVersion = document.cookie.substring(cookieStart + 6, cookieEnd); 
}

// If the cookie doesn't exist, perform a detection and write the cookie
else {
	flashVersion = flashDetect();
	document.cookie = 'flash=' + flashVersion;
}

// For the situation where we can't detect, set the values of the reference variables
if (flashVersion == 'dontKnow') {
	flashVersion = 0;
	dontKnow = true;
}
