/**
 * @version		1.0.1, 2005-07-19
 * @author		Roman Hipper
 * @author 		(based on a script by Michael Williams - http://www.macromedia.com/devnet/flashplayer/articles/future_detection.html)
 * @description	Automatically instanciated when flashDetection.js is linked to the HTML-Document.
 */
function FlashDetection(){
	this.__detectBrowser();
	this.__jsdetect	= this.__initDetectionRoutine();
}
var p			= FlashDetection.prototype;
p.useRedirect	= false;
p.flashPage		= null;
p.noFlashPage	= null;
p.flashVersion	= null;
p.__isIE		= false;
p.__isWin		= false;
p.__isOpera		= false;
p.__jsdetect	= null;

/*
 * detectVersion
 * @param	Number	(optional) required major version
 * @param	Number	(optional) required minor version
 *
 * @return	- Boolean if at least reqMajorVersion is supplied<br />
 *			- String  if called without parameters (detected Flashversion, format: "6.65");
 */
p.detectVersion = function(reqMajorVer, reqMinorVer){
	if (typeof(reqMinorVer) == 'undefined') reqMinorVer = 0;
	var versionStr, tempArray, tempString, versionArray, versionMajor, versionMinor, versionNum;
	var reqVer	= parseFloat(reqMajorVer + "." + reqMinorVer);
	for (var i = 26; --i > 0;) {
		versionStr	= (this.__jsdetect) ? this.__getSwfVer(i) : VBGetSwfVer(i);
		if (versionStr == -1) {
			if(this.useRedirect) this.__redirect(false);
			return false;
		} else if (versionStr != 0) {
			if(this.__isIE && this.__isWin && !this.__isOpera) {
				tempArray		= versionStr.split(" ");
				tempString		= tempArray[1];
				versionArray	= tempString .split(",");
				versionMajor	= versionArray[0];
				versionMinor	= versionArray[2];
				versionString	= versionMajor + "." + versionMinor;
				versionNum		= parseFloat(versionString);
			} else {
				versionNum		= versionStr;
			}
			this.flashVersion	= versionNum;
			if(typeof(reqMajorVer) == 'undefined'){
				return versionNum;
			}else{
				var retVal	= (versionNum >= reqVer ? true : false );
				if(this.useRedirect) this.__redirect(retVal);
				return retVal;
			}            
		}
	}
	return (reqVer ? false : this.flashVersion);
}

p.__detectBrowser = function(){
	this.__isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
	this.__isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
	this.__isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
};

p.__initDetectionRoutine = function(){
	if(this.__isIE && this.__isWin && !this.__isOpera){
		document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
		document.write('Function VBGetSwfVer(i) \n');
		document.write('on error resume next \n');
		document.write('Dim swControl, swVersion \n');
		document.write('swVersion = 0 \n');
		document.write('set swControl = CreateObject("ShockwaveFlash.ShockwaveFlash." + CStr(i)) \n');
		document.write('if (IsObject(swControl)) then \n');
		document.write('swVersion = swControl.GetVariable("$version") \n');
		document.write('end if \n');
		document.write('VBGetSwfVer = swVersion \n');
		document.write('End Function \n');
		document.write('</SCR' + 'IPT\> \n');
		return false;
	}else{
		return true;
	}
};

p.__redirect = function(ok){
	if (ok) {
		if(this.flashPage == null) window.alert("No 'flashPage' defined.");
		else window.location.replace(this.flashPage);
	} else {
		if(this.noFlashPage == null) window.alert("No 'noFlashPage' defined.");
		else window.location.replace(this.noFlashPage);
	}
};

p.__getSwfVer = function(){
	var swVer2, flashDescription, descArray, tempArrayMajor, versionMajor, tempArrayMinor, versionMinor, flashVer;
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]){
			swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			descArray = flashDescription.split(" ");
			tempArrayMajor = descArray[2].split(".");
			versionMajor = tempArrayMajor[0];
			if ( descArray[3] != "" ) {
				tempArrayMinor = descArray[3].split("r");
			} else {
				tempArrayMinor = descArray[4].split("r");
			}
			versionMinor = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
			flashVer = parseFloat(versionMajor + "." + versionMinor);
		} else {
			flashVer = -1;
		}
	}else if(navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1){
		flashVer = 4;
	}else if(navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1){
		flashVer = 3;
	}else if(navigator.userAgent.toLowerCase().indexOf("webtv") != -1){
		flashVer = 2;
	}else{
		flashVer = -1;
    }
	return flashVer;
};

delete p;

var flashDetection = new FlashDetection();

