/**
 * @var		array/string
 * @access	private
 * @desc	プラグインダウンロードページ
 */
var downloadpage = new Array();
// English
downloadpage[0] = "http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash";
// Japanese
downloadpage[1] = "http://www.macromedia.com/jp/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash";

/**
 * @var		int
 * @access	private
 * @desc	プラグインバージョン
 */
var pluginVer = 0;

// 処理不能の場合の代替処理を実行します。
// nonflash_SW が 0 の場合は内容を返し、1 の場合はリダイレクトを行います。
function pfAltAction(Obj) {

	if( Obj.nonflashSW == 1 ){

		location.href = Obj.nonFlashSRC;
	}else{

		return Obj.nonFlashSRC;
	}
}

/**
 * @method	mSetAltContent
 */
// 代替内容を取得します。
// nonflash_SW が 0 の場合は内容を返し、1 の場合は返しません。
// (nonflash_SW = 1 のときは代替 = リダイレクトなので代替内容不要)
function mSetAltContent( passobj ){

	if( passobj.nonflashSW == 1 ){

		return "";
	}else{

		return passobj.nonFlashSRC;
	}
}

/**
 * @method	mGetSwfObject
 * @return	Boolean	プラグイン未検出
 * @[desc	SWF Player のバージョンを取得して値を返す
 */
function mGetSwfObject() {

	if( navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"] ){

		return( navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin );
	}else{

		return false;
	}
}

/**
 * @method	putflash
 * @param	object	SWF生成パラメータ格納オブジェクト
 * @return	void
 * @access	public
 * @desc
 */
function putflash( passobj ){

	// 各プロパティ初期化 (但し、初期状態では条件不足)
	/**
	 * @var		String
	 * @desc	SWF ファイル格納ディレクトリ（相対パス）
	 */
	if( !passobj.dir ) passobj.dir = '';
	/**
	 * @var		String
	 * @desc	出力 SWF のオブジェクト ID
	 */
	if( !passobj.id ) passobj.id = '';
	/**
	 * @var		int
	 * @desc	必須プラグインバージョン
	 */
	if( !passobj.requiredVer ) passobj.requiredVer = 6;
	/**
	 * @var		String(Color)
	 * @desc	SWF 出力時の背景色
	 */
	if( !passobj.bgcolor ) passobj.bgcolor = "#ffffff";
	/**
	 * @var		String
	 * @desc	SWF レンダリングクオリティ
	 */
	if( !passobj.quality ) passobj.quality = "high";
	/**
	 * @var		int
	 * @desc	使用言語
	 */
	if( !passobj.language ) passobj.language = 1;
	if( !passobj.macie4exec && passobj.macie4exec != "0" ) passobj.macie4exec = 0;
	if( !passobj.moz_exec && passobj.moz_exec != "0" ) passobj.moz_exec = 1;
	if( !passobj.opera_exec && passobj.opera_exec != "0" ) passobj.opera_exec = 0;
	if( !passobj.nonflashSW && passobj.nonflashSW != "0" ) passobj.nonflashSW = 0;
	if( !passobj.nonFlashSRC ) passobj.nonFlashSRC = "";
	if( !passobj.swLiveConnect ) passobj.swLiveConnect = "false";
	if( !passobj.menu ) passobj.menu = "false";
	if( !passobj.disableCodebase ) passobj.disableCodebase = 0;
	if( !passobj.flashvars ) passobj.flashvars = '';

	// プラグインチェック
	var plugin = mGetSwfObject();

	if( plugin ){

		pluginVer = parseInt( plugin.description.substring( plugin.description.indexOf(".") -1 ));
	}else{

		// Windows/MSIE 環境
		document.writeln( '<script type="text/vbscript">' );
		document.writeln( 'On Error Resume Next' );
		document.writeln( 'Private swfEnableFlag' );
		document.writeln( 'swfEnableFlag = false' );
		document.writeln( 'swfEnableFlag = IsObject( CreateObject( "ShockwaveFlash.ShockwaveFlash.' + passobj.requiredVer + '" ))' );
		document.writeln( 'If swfEnableFlag Then' );
		document.writeln( 'pluginVer = ' + passobj.requiredVer );
		document.writeln( 'End If' );
		document.writeln( '</script>' );
	}

	// HTMLソース出力
	document.open();

	// ヘッドソースがある場合はヘッドソースを出力
	if( passobj.hedSRC ){

		document.write( passobj.hedSRC );
	}

	// 必須プラグイン条件を満たしている場合は OBJECT 要素を出力
	// 必須プラグイン条件を満たしていない場合は代替コンテンツを出力
	if( pluginVer < passobj.requiredVer ){

		document.write( pfAltAction( passobj ));
	}else{

 		document.write( pfGetObjectElement( passobj ));
	}

	// フットソースがある場合はフットソースを出力
	if( passobj.fotSRC ){

		document.write( passobj.fotSRC );
	}

	document.close();
}

function pfGetObjectElement(Obj){
	// object要素 (と、その中の代替内容) を生成します。

	// Opera の場合、Opera_exec = 1 の場合のみ内容を出力する。
	// そうでなければ代替内容を表示して終了。
	if( window.opera && Obj.opera_exec != 1 ){

		return pfAltAction( Obj );
	}

	// パラメータが揃っていなければ空文字列を返す
	if( !Obj.file || !Obj.width || !Obj.height || !Obj.id ){

		return "";
	}

	// object要素生成
	var result = "";
	result += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';

	if( !Obj.disableCodebase ){

		result += ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"';
	}

	result += ' id="' + Obj.id + '" width="' + Obj.width + '" height="' + Obj.height + '" name="' + Obj.id + '">';
	result += '<param name="movie" value="' + Obj.dir + Obj.file + '">';
	result += '<param name="quality" value="' + Obj.quality + '">';
	result += '<param name="bgcolor" value="' + Obj.bgcolor + '">';
	result += '<param name="menu" value="' + Obj.menu + '"' + '>';
	result += '<param name="flashvars" value="' + Obj.flashvars + '"' + '>';
	if( Obj.salign ){

		result += '<param name="salign" value="' + Obj.salign + '"' + '>';
	}
	if( Obj.scale ){

		result += '<param name="scale" value="' + Obj.scale + '"' + '>';
	}

	// 非オペラ、Windows MSIE 時には指定された代替内容を出力。
	// オペラ + 強制出力の場合は強制的に embed 出力となる。
	if(( navigator.appVersion.indexOf( 'Win', 0 ) != -1 && navigator.appName.indexOf( "Microsoft Internet Explorer", 0 ) != -1 ) && !window.opera ){

		result += mSetAltContent( Obj );
	} else {

		result += pfGetEmbedElement( Obj );
	}

	result += '</object>';

	return result;
}

function pfGetEmbedElement( Obj ){
	// 必要に応じてembed要素を出力します。
	// ただし以下の条件のいずれかに該当するときは embed は出力せず、代替を出力します。
	// ・Gecko, Mac MSIE4, Mac MSIE3 である。ただし強制実行オプション指定時は強制的に embed 出力。

	// Gecko で、かつ強制実行でない
	if( Obj.moz_exec != 1 && ( navigator.userAgent.indexOf( "Gecko/" ) != -1 )){

		return pfAltAction( Obj );
	}

	// Mac で、かつ強制実行でない
	if( Obj.macie4exec != 1 && ( navigator.appVersion.indexOf( 'Mac', 0 ) != -1 )){

		if( navigator.appVersion.indexOf( 'MSIE 4.', 0 ) != -1 ){

			return pfAltAction( Obj );
		}
		if( navigator.appVersion.indexOf( 'MSIE 3.', 0 ) != -1 ){

			return pfAltAction( Obj );
		}
	}

	var result = "";
	result += '<embed src="' + Obj.dir + Obj.file + '"';
	result += ' menu="' + Obj.menu + '"';
	result += ' quality="' + Obj.quality + '"';
	result += ' swLiveConnect="' + Obj.swLiveConnect + '"';
	result += ' bgcolor="' + Obj.bgcolor + '"';
	result += ' width="' + Obj.width + '"';
	result += ' height="' + Obj.height + '"';
	if( Obj.salign ){

		result += ' salign="' + Obj.salign + '"';
	}
	if( Obj.scale ){

		result += ' scale="' + Obj.scale + '"';
	}
	result += ' type="application/x-shockwave-flash"';
	result += ' pluginspage="' + downloadpage[Obj.language] + '"';
	result += ' name="' + Obj.id + '"';
	result += ' flashvars="' + Obj.flashvars + '"';
	result += '></embed><br>';

	return result;
}