
// ブラウザのバージョン判定
function versionCheck( )
{
	var flag = ( ( OPERA && getBrowserVersion( ).substr( 0, 1 ) >= 6 ) || ( NN4 && getBrowserVersion( ).substr( 0, 3 ).toString( ) != '4.0' ) || IE5 || NN6 ) ? true : false ;

	return flag ;
}

// FLASH のバージョン判定
function getFlashVersion( )
{
	var flashVersion ;
	var usrOS = getOsName( ).toLowerCase( ) ;

	if ( WIN && document.all && !OPERA )
	{
		flashVersion = getVBFlashVersion( ) ;
	}
	else
	{
		flashVersion = getJSFlashVersion( ) ;
	}

	return flashVersion ;
}

// WIN + MSIE 以外のブラウザは JS で判定する
function getJSFlashVersion( )
{
	var PLUGIN = navigator.plugins ;
	var PLUGIN_LENGTH = PLUGIN.length ;
	var myPlugin ;
	var myName ;
	var myDesc ;
	var flashVersion ;
	var versionDemilita = " r" ;
	var demilitaPos ;
	var majorVersion ;
	var minorVersion ;

	for ( var i=0; i < PLUGIN_LENGTH; i++ )
	{
		myPlugin = PLUGIN[ i ] ;
		myName = myPlugin.name ;
		myDesc = myPlugin.description ;

		if ( myName.indexOf( "Shockwave" ) != -1 && myName.indexOf( "Flash" ) != -1 )
		{
			flashVersion = myDesc.substring( myDesc.indexOf("Flash ") + 6 ) ;
			demilitaPos = flashVersion.indexOf( versionDemilita ) ;

			if ( demilitaPos != -1 )
			{
				majorVersion = flashVersion.substring( 0, demilitaPos ) ;
				minorVersion = parseInt( flashVersion.substring( demilitaPos + 2 ) ) ;

				if ( minorVersion < 10 )
				{
					minorVersion = "0" + minorVersion ;
				}

				return parseFloat( majorVersion + minorVersion ) ;
			}
			else
			{
				return parseFloat( flashVersion ) ;
			}
		}
	}

	return Number( 0 ) ;
}

// WIN + MSIE の場合、VBScript にて判定する
function getVBFlashVersion( )
{
	var COUNT_MAX = 7 ; // 最初に調べるバージョン
	var flashVersion ;
	var majorVersion ;
	var minorVersion ;

	for ( var i=COUNT_MAX; i>0; i-- )
	{
		flashVersion = getFlashControlVersion( i ) ;

		if ( flashVersion != 0 )
		{
			majorVersion = flashVersion >> 16 ;
			minorVersion = flashVersion & 0x0000ffff ;

			return parseFloat( majorVersion + "." + minorVersion ) ;
		}
	}

	return Number( 0 ) ;
}



/* ------------------------------------------------------------------------------------
   FlashPlayerのプラグインを調べ、問題無いときはSWFを書き出し、NGの時は静止画を表示する
------------------------------------------------------------------------------------ */
function FlashDispatcher( requestVersion, swfFile, altImage, width, height, JumpURL )
{
	this.requestVersion = requestVersion ;
	this.swfFile = swfFile ;
	this.altImage = altImage ;
	this.width = width ;
	this.height = height ;

	if ( JumpURL )
	{
		this.pageJump( JumpURL ) ;
	}
}

// ジャンプ先が指定してあった場合、静止画像ではなく、ページを切り替える
FlashDispatcher.prototype.pageJump = function( JumpURL )
{
	var targetBrowser = versionCheck( ) ;
	var flashVersion  = getFlashVersion( ) ;

	if ( !targetBrowser || flashVersion < this.requestVersion )
	{
		location.replace( JumpURL ) ;
	}
}

// ブラウザか、プラグインがこちらの要求以下だった場合は静止画像を書き出す
// ※thisPageVisited にtrue を渡すと、静止画像を表示する
//  （cookieで二度目以降は静止画を表示したい時に用いる）
FlashDispatcher.prototype.writeContents = function( thisPageVisited )
{
	var targetBrowser = versionCheck( ) ;
	var flashVersion  = getFlashVersion( ) ;

	if ( targetBrowser )
	{
		document.open( ) ;

		if ( flashVersion < this.requestVersion || thisPageVisited )
		{
			document.write( '<img src="' +this.altImage+ '" width="' +this.width+ '" height="' +this.height+ '" alt="" border="0">' ) ;
		}
		else
		{
			document.write( '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="' +this.width+ '" height="' +this.height+ '" id="flashDispatcher" align="">' ) ;
			document.write( '<param name="movie" value="' +this.swfFile+ '">' ) ;
			document.write( '<param name="quality" value="high">' ) ;
			document.write( '<param name="bgcolor" value="#FFFFFF">' ) ;
			document.write( '<embed src="' +this.swfFile+ '" quality="high" bgcolor="#ffffff"  width="' +this.width+ '" height="' +this.height+ '" name="flashDispatcher" align="" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>' ) ;
			document.write( '</object>' ) ;
		}

		document.close( ) ;
	}
	else
	{
		document.write( '<img src="' +this.altImage+ '" width="' +this.width+ '" height="' +this.height+ '" alt="" border="0">' ) ;
	}
}