/*
 * flash.js
 * Flash関連処理クラス定義
 *
 * $Id$
 *
 */


/*
 * Browser()
 * ユーザのブラウザ環境クラスのコンストラクタ
 *
 * プロパティ：
 * b		ブラウザ、IEならば"ie"NNならば"ns"
 * pf		プラットホーム、Windowsならば"win32"Macintoshならば"mac"それ
 * 		以外は"other"
 * version	マイナーバージョンも含めたバージョン
 * v		メジャーバージョン
 *
 */
function Browser()
{
	var b = navigator.appName;
 	var ua = navigator.userAgent.toLowerCase();

	if ( b == "Netscape" ) { this.b = "ns"; }
	else if ( b == "Microsoft Internet Explorer" ) { this.b = "ie"; }
	else { this.b=b }

	if ( ua.indexOf("win") > -1 ) { this.pf = "win32"; }
	else if ( ua.indexOf("mac") > -1 ) { this.pf = "mac"; }
	else { this.pf = "other"; }

	this.version = navigator.appVersion;
	this.v = parseInt(this.version);
}


/*
 * SwfControl(br)
 * Flash管理クラスのコンストラクタ
 *
 * プロパティ：
 * br	ユーザのブラウザ環境オブジェクトのリファレンス
 * var	ユーザのFlashPlayerのバージョン（WINIE4+は除く）
 * rev	ユーザのFlashPlayerのリビジョン（WINIE4+は除く）
 *
 */
function SwfControl(br)
{
	var np = navigator.plugins;
	var nm = navigator.mimeTypes;
	var words;

	this.br = br;

	if ( np && np[SwfControl.PLUGIN_NAME] &&
	     nm && nm[SwfControl.MIMETYPE] &&
	     nm[SwfControl.MIMETYPE].enabledPlugin ) {
		words = np[SwfControl.PLUGIN_NAME].description.split(" ");

		for ( i = 0; i < words.length; ++i) {
			if (isNaN(parseInt(words[i]))) { continue; }
			this.ver = words[i];
			this.rev = parseInt(words[i+1].substring(1));
		}
	}
	
}

SwfControl.PLUGIN_NAME = 'Shockwave Flash';
SwfControl.MIMETYPE    = 'application/x-shockwave-flash';
SwfControl.CLASSID     = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000';
SwfControl.CODEBASE    = 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0';
SwfControl.PLUGINSPAGE = 'http://www.macromedia.com/jp/shockwave/download/?P1_Prod_Version=ShockwaveFlash&Lang=Japanese';


/*
 * SwfControl.enable_flash(ver, rev)
 * 引数でしたバージョンよりも上位のFlashPlayerかどうか調べる
 *
 * 引数：
 * var	ユーザのFlashPlayerのバージョン
 * rev	ユーザのFlashPlayerのリビジョン
 *
 */
SwfControl.prototype.enable_flash = function(ver, rev)
{
	var np = navigator.plugins;
	var nm = navigator.mimeTypes;

	if ( np && np[SwfControl.PLUGIN_NAME] &&
	     nm && nm[SwfControl.MIMETYPE] &&
	     nm[SwfControl.MIMETYPE].enabledPlugin ) {
		return ( this.ver > ver ||
			 (this.ver == ver && this.rev >= rev) ) 
			? true : false;
	}
	else if ( this.br.pf == 'win32' &&
		  this.br.b  == 'ie' &&
		  this.br.v  >= 4 ) {
		return true;
	}
	else { return false; }
}

/*
 * SwfControl.load_swf(swf, w, h, name, noscript)
 * swfのためのHTMLを出力する。
 *
 * 引数：
 * swf	swfファイルのパス
 * w	swfの幅
 * h	swfの高さ
 * name	名前
 * noscript	JavaScriptが利用できない場合の代替HTML
 *
 */
SwfControl.prototype.load_swf = function(swf, w, h, name, noscript)
{
	document.open();

	if ( this.br.pf == 'win32' && this.br.b  == 'ie' ) {
		document.write('<object classid="' + SwfControl.CLASSID +
			       '" id="' + name +
			       '" codebase="' + SwfControl.CODEBASE +
			       '" width="'+ w +
			       '" height="'+ h +
			       '" style="margin:0px;">');
		document.write('<param name="movie" value="'+ swf + '">');
		document.write('<param name="quality" value="high">');
		document.write('<param name="wmode" value="transparent">');
		document.write('<param name="menu" value="false">');
		document.write('<param name="bgcolor" value="'+ document.bgColor + '">');
		document.write(noscript);
		document.write('<\/object>');
	}
	else {
		document.write('<embed name="'+ name +
			       '" src="'+ swf +
			       '" width="'+ w +
			       '" height="'+ h +
			       '" menu="false" quality="high" wmode="transparent" bgcolor="' +
			       document.bgColor +
			       '" type="' + SwfControl.MIMETYPE +
			       '" pluginspage="' + SwfControl.PLUGINSPAGE +
			       '"><\/embed>');
	}

	document.close();
}



