if( !Chum_FlashDetectInited )
{
	var Chum_FlashDetectInited = true;

	function FlashDetector()
	{
		//alert("Nav.AppVersion: " + navigator.appVersion);
		//alert("Nav.AppName: " + navigator.appName);
		//alert("Nav.UserAgent: " + navigator.userAgent);
		//alert("Nav.Platform: " + navigator.platform);
		this.Movies = new Array();
		
		this.browserSniff();
		this.init();
	};
	
	// Flash items on the page (element ids)
	FlashDetector.prototype.Movies = null;
	
	// misc properties
	FlashDetector.prototype.$maxVersion = 9;
	FlashDetector.prototype._version = 0;
	FlashDetector.prototype._MajorVersion = 0;
	FlashDetector.prototype._MinorVersion = 0;	
	
	FlashDetector.prototype.defaultAltContent = '<style>\n';
	FlashDetector.prototype.defaultAltContent += 'table.getFlash tr td\n{\n';
	FlashDetector.prototype.defaultAltContent += '\tfont-family: verdana, arial, helvetica, sans-serif;\n';
	FlashDetector.prototype.defaultAltContent += '\tfont-size: 11px;\n';
	FlashDetector.prototype.defaultAltContent += '}\n';
	FlashDetector.prototype.defaultAltContent += 'a.gfAnchor:link, a.gfAnchor:visited, a.gfAnchor:active \n{\n';
	FlashDetector.prototype.defaultAltContent += '\tfont-family: verdana, arial, helvetica, sans-serif;\n';
	FlashDetector.prototype.defaultAltContent += '\tfont-size: 11px;\n';
	FlashDetector.prototype.defaultAltContent += '\tfont-weight: bold;\n';
	FlashDetector.prototype.defaultAltContent += '\ttext-decoration: none;\n';
	FlashDetector.prototype.defaultAltContent += '}\n';
	FlashDetector.prototype.defaultAltContent += 'a.gfAnchor:hover\n{\n';
	FlashDetector.prototype.defaultAltContent += '\tfont-family: verdana, arial, helvetica, sans-serif;\n';
	FlashDetector.prototype.defaultAltContent += '\tfont-size: 11px;\n';
	FlashDetector.prototype.defaultAltContent += '\tfont-weight: bold;\n';
	FlashDetector.prototype.defaultAltContent += '\ttext-decoration: underline;\n';
	FlashDetector.prototype.defaultAltContent += '}\n';
	FlashDetector.prototype.defaultAltContent += '.gfHead\n{\n';
	FlashDetector.prototype.defaultAltContent += '\tfont-weight: bold;\n';
	FlashDetector.prototype.defaultAltContent += '}\n';	
	FlashDetector.prototype.defaultAltContent += '</style>\n';
	FlashDetector.prototype.defaultAltContent += '<table class="getFlash" width="100%" height="100%" border="0" cellpadding="6" cellspacing="0"><tr><td valign="top">';
	FlashDetector.prototype.defaultAltContent += '<span class="gfHead">You\'re not getting the experience!</span><br>';
	FlashDetector.prototype.defaultAltContent += '<p>In order to view this content, you need to install the latest version of the free Flash player from Macromedia. The links below will open in a new window - once you have installed the Flash Player, come back and refresh this page.<br><br>';
	FlashDetector.prototype.defaultAltContent += '<a class="gfAnchor" href="http://www.macromedia.com/go/getflashplayer/" target="_blank">&raquo; Click here to install the free Flash Player now!</a><br><br>';
	FlashDetector.prototype.defaultAltContent += '<a class="gfAnchor" href="http://www.macromedia.com/go/flashplayer/" target="_blank">&raquo; Click here for more information about the Macromedia Flash Player.</a><br></p>';
	FlashDetector.prototype.defaultAltContent += '<div align="center"><a href="http://www.macromedia.com/go/getflashplayer"><img src="http://www.macromedia.com/images/shared/download_buttons/get_flash_player.gif" border="0"></a></div><br>';
	FlashDetector.prototype.defaultAltContent += 'For the best experience, we also recommend that you install the most current version of your preferred browser.<br><br>';
	FlashDetector.prototype.defaultAltContent += '<ul>';
	FlashDetector.prototype.defaultAltContent += '<li><a class="gfAnchor" href="http://www.microsoft.com/windows/ie/default.asp" target="_blank">Internet Explorer (PC)</a></li>';
	FlashDetector.prototype.defaultAltContent += '<li><a class="gfAnchor" href="http://www.microsoft.com/mac/products/internetexplorer/internetexplorer.aspx?pid=internetexplorer" target="_blank">Internet Explorer (Mac)</a></li>';
	FlashDetector.prototype.defaultAltContent += '<li><a class="gfAnchor" href="http://channels.netscape.com/ns/browsers/default.jsp" target="_blank">Netscape 7 (PC/Mac)</a></li>';
	FlashDetector.prototype.defaultAltContent += '<li><a class="gfAnchor" href="http://www.apple.com/safari/" target="_blank">Safari (Mac)</a></li>';
	FlashDetector.prototype.defaultAltContent += '</ul><br>';
	FlashDetector.prototype.defaultAltContent += '</td></tr></table>';
	
	// Browser Info Props
	FlashDetector.prototype._isIE = false;
	FlashDetector.prototype._isWin = false;
	FlashDetector.prototype.altBrowsers = [ "opera", "safari", "konqueror", "netscape", "firefox" ];
	
	FlashDetector.prototype.init = function()
	{
		if( this._isIE && this._isWin && window.ActiveXObject )
		{
			this._version = this.checkFlashActiveX();
			
			// because browsers like Opera and Firefox can identify as IE,
			// 	if we don't have a version from the above, check using the Netscape plugin
			//	detection code as well, just in case this is not really IE
			//if( !window.ActiveXObject )
			//{
			//	this._version = this.checkFlashNS();	
			//}
		}
		else
		{
			this._version = this.checkFlashNS();
		}
		//alert("Installed Flash Version: " + this._version);
	};
	
	FlashDetector.prototype.browserSniff = function()
	{
		var ua = navigator.userAgent.toLowerCase();
		this._isIE = ( ua.indexOf( "msie" ) != -1 ) ? true : false;
		if( this._isIE )
		{
			for(var i=0; i<this.altBrowsers.length; i++ )
			{
				if( ua.indexOf( this.altBrowsers[ i ] ) != -1 )
				{
					this._isIE = false;
					break;
				}
			}
		}
		this._isWin = ( ua.indexOf( "windows" ) != -1 ) ? true : false;
	};
	
	FlashDetector.prototype.checkFlashActiveX = function()
	{
		if( !this._isIE || !this._isWin || !window.ActiveXObject ) return 0;
	
		//var fObj;
		var c = 0;
		// runs the try/catch through an eval
		// so it doesn't break in older browsers
		// with older JS engines
		
		//eval( "for( i=this.$maxVersion; i>2; i-- ){ try { var fObj = new ActiveXObject( \"ShockwaveFlash.ShockwaveFlash.\" + i ); c = i; break; } catch( e ){} }" );
		//eval( "for( i=this.$maxVersion; i>2; i--) { try { fObj = new ActiveXObject( \"ShockwaveFlash.ShockwaveFlash.\" + i ); var versionString = fObj.getVariable( \"$version\" ); alert( versionString ); if( versionString == \"\" ) { this._MajorVersion = i; } else { versionString = versionString.substring( versionString.indexOf( \" \" ) + 1 ); var parts = versionString.split( \",\" ); this._MajorVersion = parseInt( parts[ 0 ] ); this._MinorVersion = parseInt( parts[ 2 ] ); } c = i; break; } catch ( e ) {} }" );
		
		var isDebug = false;
		if( document.location.toString().indexOf( "DEBUG" ) != -1 )
		{
			isDebug = true;	
		}
		
		
		var detectionLoop = "";
		detectionLoop += "for( i=" + this.$maxVersion + "; i>2; i--)"
		detectionLoop += "{";
		detectionLoop += 	"try";
		detectionLoop += 	"{ ";
		detectionLoop += 		"var fObj = new ActiveXObject( 'ShockwaveFlash.ShockwaveFlash.' + i ); ";
		detectionLoop +=		"this._version = i;";
		detectionLoop +=		"this._MajorVersion = i;";
		detectionLoop += 		"try";
		detectionLoop += 		"{";
		detectionLoop += 			"var versionString = fObj.getVariable( '$version' );";
		detectionLoop += 			"if( isDebug ) { alert( 'Version string: ' + versionString ); }";
		detectionLoop += 			"if( versionString == '' )";
		detectionLoop += 			"{";
		detectionLoop += 				"this._MajorVersion = i;";
		detectionLoop += 			"}";
		detectionLoop += 			"else";
		detectionLoop += 			"{ ";
		detectionLoop += 				"versionString = versionString.substring( versionString.indexOf( ' ' ) + 1 );";
		detectionLoop += 				"var parts = versionString.split( ',' );";
		detectionLoop += 				"this._MajorVersion = parseInt( parts[ 0 ] );";
		detectionLoop += 				"this._MinorVersion = parseInt( parts[ 2 ] );";
		detectionLoop += 			"}";
		detectionLoop += 		"}"
		detectionLoop += 		"catch( versionError )";
		detectionLoop += 		"{";
		detectionLoop += 			"if( isDebug )";
		detectionLoop += 			"{";
		detectionLoop += 				"var msg = 'Error detecting version:\\n';";
		detectionLoop += 				"for( var prop in versionError ) { msg += prop + ': ' + versionError[ prop ] + '\\n'; }";
		detectionLoop += 				"alert( msg );";
		detectionLoop += 			"}";
		detectionLoop += 		"}";
		detectionLoop += 		"c = i;";
		detectionLoop += 		"delete( fObj );";
		detectionLoop += 		"break;";
		detectionLoop += 	"}";
		detectionLoop += 	"catch ( activeXCreationError )";
		detectionLoop += 	"{";
		detectionLoop += 		"if( isDebug )";
		detectionLoop +=		"{";
		detectionLoop +=			"var msg = 'Error creating active x control (' + i + ')\\n';";
		detectionLoop +=			"for( var prop in activeXCreationError ) { msg += prop + ': ' + activeXCreationError[ prop ] + '\\n'; }";
		detectionLoop +=			"alert( msg );";
		detectionLoop +=		"}";
		detectionLoop += 	"}";
		detectionLoop += "}"
		
		// try/catch for debug only (as it will break older browsers that do not support try/catch
		
		//try
		//{
			eval( detectionLoop );
		//}
		//catch( e )
		//{
		//	if( isDebug )
		//	{
		//		var msg = "Error running detection loop:\n";
		//		for( var prop in e )
		//		{
		//			msg += prop + ": " + e[ prop ] + "\n";
		//		}
		//		alert( msg );
		//	}
		//}
		
		
		
		/*
		// this the (formatted) code of the above eval statement
		for( i=this.$maxVersion; i>2; i--)
		{
			try
			{
				var fObj = new ActiveXObject( "ShockwaveFlash.ShockwaveFlash." + i );
				
				var versionString = fObj.getVariable( "$version" );
				if( versionString == "" )
				{
					this._MajorVersion = i;
				}
				else
				{
					versionString = versionString.substring( versionString.indexOf( " " ) + 1 );
					
					var parts = versionString.split( "," );
					this._MajorVersion = parseInt( parts[ 0 ] );
					this._MinorVersion = parseInt( parts[ 2 ] );
				}
				
				c = i;
				break;
			}
			catch( e )
			{
				// do nothing on error...just roll through
			}
		}
		*/
		return c;
	};
	
	FlashDetector.prototype.checkFlashNS = function()
	{
		if( navigator.plugins && navigator.plugins["Shockwave Flash"] )
		{
				var d = navigator.plugins["Shockwave Flash"].description;
				var versionString = d.replace( "Shockwave Flash ", "" );
				
				//var fv = parseInt( d.charAt( d.indexOf( "." ) - 1 ) );
				
				this._MajorVersion = parseInt( versionString.substring( 0, versionString.indexOf( " " ) ) );				
				this._MinorVersion = parseInt( versionString.substring( versionString.indexOf( "r" ) + 1 ) );
				
				return this._MajorVersion;
		}
		return 0;
	};
	
	FlashDetector.prototype.writeFlash = function( version, fileName, width, height, bgColor, altImage, altContent, windowMode, showMenu )
	{
		var codeBase;
		var wMode = "";
		var id = null;
		
		var major = 0;
		var minor = 0;
		var checkMinor = false;
		
		var theType = typeof( version );
		
		if( theType == "string" )
		{
			major = parseInt( version.split( "," )[ 0 ] );
			minor = parseInt( version.split( "," )[ 2 ] ) || 0;
			
				//document.write( "Version: " + version + "<br>" );
				//document.write( "Major: " + major + "[" + this._MajorVersion + "]<br>" );
				//document.write( "Minor: " + minor + "[" + this._MinorVersion + "]<br>" );
			
			version = parseInt( version );
			
			if( minor != null && minor != 0 )
			{
				checkMinor = true;	
			}
			
			codebase = "version=" + version;
		}
		else
		{
			codeBase = "version=" + version + ",0,0,0";
		}
		
		if( typeof( windowMode ) != "undefined" )
		{
			if( windowMode == "opaque" || windowMode == "transparent" || windowMode == "window" )
			{
				wMode = windowMode;
			}
		}
		
		if( showMenu !== true )
		{
			showMenu = false;
		}
		
		var installedVersionIsAcceptable = false;
		
		if( checkMinor )
		{
			installedVersionIsAcceptable = ( this._MajorVersion > major ) || ( this._version > major ) || ( this._MajorVersion == major && this._MinorVersion >= minor );	
		}
		else
		{
			installedVersionIsAcceptable = ( this._version >= version ) || ( this._MajorVersion >= version );
		}
		
		if( installedVersionIsAcceptable )
		{
			if( bgColor.length == 4 )
			{
				bgColor = "#" + bgColor.substr( 1, 3 ) + bgColor.substr( 1, 3 );
			}
			else if( bgColor.length == 3 )
			{
				bgColor = "#" + bgColor + bgColor;
			}
			else if( bgColor.length == 6 )
			{
				bgColor = "#" + bgColor;
			}
		
			// set the codebase/classid attributes based on version number
			var id = "flash_" + this.Movies.length;
			
			/*if( version == 6)
			{
				codeBase = "version=6,0,0,0";
			}
			else if( version == 7)
			{
				codeBase = "version=7,0,14,0";
			}*/
			
			//var id = fileName.substring(fileName.lastIndexOf("/")+1, fileName.lastIndexOf(".")-1);
			
			//clsid:D27CDB6E-AE6D-11cf-96B8-444553540000
			//clsid:D27CDB6E-AE6D-11cf-96B8-444553540000
			//http://download.macromedia.com/pub/shockwave/cabs/ flash/swflash.cab#version=4,0,2,0
			//http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#
			document.write( '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#'+ codeBase +'" id="' + id + '"width="' + width + '" height="' + height + '">' );
			document.write( '<param name="movie" value="' + fileName + '">' );
			document.write( '<param name="quality" value="high">' );
			if( !showMenu ) { document.write( '<param name="menu" value="false">' ); }
			document.write( '<param name="loop" value="true">' );
			document.write( '<param name="allowfullscreen" value="true">' );
			document.write( '<param name="allowscriptaccess" value="always">' );
			document.write( '<param name="bgcolor" value="' + bgColor + '">' );
			document.write( '<param name="stretching" value="exactfit">' );
			if( wMode != "" )
				{ document.write( '<param name="wmode" value="' + wMode + '">' ); }
			
			document.write( '<embed src="'+ fileName +'" name="' + id + '"' );
			document.write( ' width="' + width + '" height="' + height + '"' );
			document.write( ' quality="high"' );
			if( !showMenu ) { document.write( ' menu="false"' ); }
			document.write( ' bgcolor="'+ bgColor +'"' );
			document.write( ' loop="true"' );
			document.write( ' allowfullscreen="true"' );
			document.write( ' allowscriptaccess="always"' );
			document.write( ' swliveconnect="true"' );
			
			if( wMode != "" )
				{ document.write( ' wmode="' + wMode + '"' ); }
			
			document.write( ' type="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">' );
			document.write( '</embed>' );
			document.write( '</object>' );
			
			this.Movies.push( id );
			
			return id;
		}
		else
		{
			if( ( !altContent || altContent == "" ) && ( !altImage || altImage == "" ) )
			{
				document.write( this.defaultAltContent );
			}
			else
			{
				if( altContent )
				{
					document.write( altContent );
				}
				else
				{
					document.write( '<a href="http://www.macromedia.com/go/getflashplayer" target="_blank"><img src="' + altImage + '" width="' + width + '" height="' + height + '" border="0" alt="Get Flash!"></a>');
				}
			}
		}
		
		return null;
	};
	
	var _fd = new FlashDetector();
	
	function writeFlash( version, fileName, width, height, bgColor, altImage, altContent, windowMode, showMenu )
	{
		return _fd.writeFlash( version, fileName, width, height, bgColor, altImage, altContent, windowMode, showMenu );
	}
}
