/*
	--------------------------------
	Last Updated: 2006.04.24
	--------------------------------
	- Table of Contents -

	1. CONFIGURATION

	2. FUNCTION CALLS
		- // TrapDisabledFlash ( Flash_RequireVer, RedirectLoc )

	3. FUNCTIONS
		- TrapDisabledFlash ( )
		- WriteFlashSrc ( )
		- IncludeFlashSrc ( )
		- IsEnabledFlash ( )
		- IsEnabledFlashVer ( )
		- GetFlashVer ( )
		- GetFlashVerByVBS ( )
		- GetFlashVerByJS ( )
		- SetIsActiveFlash ( )
	--------------------------------
*/



/* --------------------------------
	1. CONFIGURATION
-------------------------------- */

// 要求バージョン
// var Flash_RequireVer = 5;

// リダイレクト先のアドレス
// var RedirectLoc = 'index-nonflash.html';



// 現行の最終バージョン
var Flash_LatestVer = 8;



/* --------------------------------
	2. FUNCTION CALLS
-------------------------------- */

// TrapDisabledFlash ( Flash_RequireVer, RedirectLoc );



/* --------------------------------
	3. FUNCTIONS
-------------------------------- */

/* Flashの動作可否を判定のうえ、不可の際はリダイレクト先へ移動 ---------------- */
function TrapDisabledFlash ( RequireVer, RedirectLoc ) {
	if ( !IsEnabledFlash ( RequireVer ) ) { location.href = RedirectLoc; }
}

/* Flashの動作可否を判定のうえ、結果に基づいた内容を出力 ---------------- */
function WriteFlashSrc ( Obj ) {
	var Src = ( IsEnabledFlash ( Obj.version ) ) ? Obj.flash.join ( '\n' ) :
		( Obj.alt.length == 1 && Obj.alt[ 0 ] == null ) ? Obj.flash.join ( '\n' ) :
		Obj.alt.join ( '\n' );
	
	document.open ( );
	document.write ( Src );
	document.close ( );
}

/* HTMLにFlash要素を組み込み ---------------- */
function IncludeFlashSrc ( Obj ) {
	var Notice = '<p style="font-size: 16px;"><span style="font-size: 0.75em;">動作可能な Flash Player が検出されませんでした。</span></p>\n';

	var Src = ( IsEnabledFlash ( Obj.version ) ) ? Obj.flash.join ( '\n' ) : Notice;

	document.open ( );
	document.write ( Src );
	document.close ( );
}

/* Flashの動作可否を判定 ---------------- */
function IsEnabledFlash ( RequireVer ) {
	var State = ( GetFlashVer ( ) >= RequireVer );

	if ( State && navigator.mimeTypes[ 'application/x-shockwave-flash' ] ) {
		State = ( navigator.mimeTypes[ 'application/x-shockwave-flash' ].enabledPlugin ) ? true : false;
	}

	return State;
}

/* 要求されたバージョンのFlashの動作可否を判定 ---------------- */
function IsEnabledFlashVer ( RequireVer ) {
	return ( GetFlashVer ( ) >= RequireVer );	
}

/* Flashのバージョンを取得する処理の親関数 ---------------- */
function GetFlashVer ( ) {
	var AV = navigator.appVersion;
	var UA = navigator.userAgent;
	return ( AV.match ( 'Win' ) && !window.opera && UA.match ( 'MSIE' ) ) ? GetFlashVerByVBS ( Flash_LatestVer ) : GetFlashVerByJS ( );
}

/* VBScriptを用いたFlashのバージョンの取得 ---------------- */
function GetFlashVerByVBS ( LatestVer ) {
	SetIsActiveFlash ( );

	var Ver = false;
	for ( var I = LatestVer; I > 0; I-- ) {
		if ( IsActiveFlash ( I ) ) { Ver = I; break; }
	}

	return Ver;
}

/* JavaScriptを用いたFlashのバージョンの取得 ---------------- */
function GetFlashVerByJS ( ) {
	var Plugin = navigator.plugins;
	var Ver = false;
	for ( var I = 0; I < Plugin.length; I++ ) {
		if ( Plugin[ I ].description.match ( 'Shockwave Flash' ) ) {
			var Temp = Plugin[ I ].description.split ( ' ' );
			Ver = ( !Ver ) ? Temp[ 2 ] : ( Temp[ 2 ] > Ver ) ? Temp[ 2 ] : Ver;
		}
	}

	return Ver;
}

/* Flashのバージョン取得処理用VBScriptを出力 ---------------- */
function SetIsActiveFlash ( ) {
	var VBS_Src = [
		'<scr' + 'ipt type="text/vbscript">',
		'Function IsActiveFlash ( Ver )',
		'	on error resume next',
		'	IsActiveFlash = ( IsObject ( CreateObject ( "ShockwaveFlash.ShockwaveFlash." + CStr ( Ver ) ) ) )',
		'End Function',
		'</scr' + 'ipt>'
	];
	VBS_Src = VBS_Src.join ( '\n' );

	document.open ( );
	document.writeln ( VBS_Src );
	document.close ( );

	VBS_Src = null;
}

