
/**
 * 定数＆デフォルト値設定
 */
var EPCONST = {

	// ドメイン
	domain: "machi-log.jp",

	// swfファイルURL
	swfPath: "http://machi-log.jp/swf/ml-embplayer-v1.swf",

	// プレーヤサイズ
	size: {
		width:  "320",		// プレーヤ幅（デフォルト：320）
		height: "240"		// プレーヤ高さ（デフォルト：240）
	},

	// 再生オプション
	options: {
		autoPlay:  "0",		// 自動再生フラグ（デフォルト：OFF）
		logo:      "1",		// ロゴ表示フラグ（デフォルト：ON）
		audio:     "1",		// 音声フラグ（デフォルト：ON）
		recommend: "0",		// 推薦フラグ（デフォルト：OFF）
		mediaLink: "1",		// 拡大表示オプションフラグ(デフォルト : OFF)
		showCtlConst: "0",	// コントロールバー常時表示フラグ（デフォルト : OFF）
		quality: "0",   	// 0 低ビットレート 1 高ビットレート
		displayType: "0"	// 表示形式フラグ( 0:旧街ログ動画(4:3)、新街ログ動画(16:9) )
							/*
							 *  0: 旧街ログ動画(4:3)向け表示
							 *     ・動画をプレーヤーいっぱいの幅・高さまで広げる(比率は保持)。また上下左右でセンタリングされる。
							 *  1: 現街ログ動画(16:9)向け表示
							 *     ・旧街ログ動画向け表示の設定に加え、
							 *       コントロールバー常時表示設定であればコントロールバーの高さを引いたサイズにする。
							 *       また縦の動画位置Yは上詰めで表示される。
							 */
	},

	// プレーヤタグID
	idname: "embplayer_",
	idname_cnt: 1
}

/**
 * コンストラクタ
 *
 * @param playerid プレーヤID (省略化)
 */
function Embplayer(playerid) {
	var arg_playerid = String(playerid);
	if (playerid == undefined) {
		arg_playerid = EPCONST.idname + EPCONST.idname_cnt++;
	}
	this.pId           = arg_playerid;
	this.pWidth        = EPCONST.size.width;
	this.pHeight       = EPCONST.size.height;
	this.pAutoPlay     = EPCONST.options.autoPlay;
	this.pLogo         = EPCONST.options.logo;
	this.pAudio        = EPCONST.options.audio;
	this.pRecommend    = EPCONST.options.recommend;
	this.pMediaLink    = EPCONST.options.mediaLink;
	this.pShowCtlConst = EPCONST.options.showCtlConst;
	this.pQuality      = EPCONST.options.quality;
	this.pDisplayType  = EPCONST.options.displayType;
}

Embplayer.prototype =
{
	pId: null,
	pWidth: null,
	pHeight: null,
	pAutoPlay: null,
	pLogo: null,
	pAudio: null,
	pRecommend: null,
	pMediaLink: null,
	pShowCtlConst: null,
	pQuality:null,
	pDisplayType: null,
	pSpotId: null,
	
	/**
	 * 埋め込みプレーヤを生成する
	 *
	 * @param id　スポットID
	 */
	create: function(id)
	{
		var h = '<div id="'+this.pId+'" width="'+this.pWidth+'px" height="'+this.pHeight+'px">' + "\n"
			  + this.getPlayerTag(String(id), this.pAutoPlay, this.pLogo, this.pAudio, this.pRecommend, this.pMediaLink, this.pShowCtlConst, this.pQuality, this.pDisplayType)
			  + '</div>' + "\n";

		document.write(h);
	},
	/**
	 * プレーヤのコンテンツを変更する
	 *
	 * @param id スポットID
	 * @param ap 自動再生フラグ(省略化)
	 * @param lg ロゴ表示フラグ(省略化)
	 * @param au 音声フラグ(省略化)
	 * @param rc 推薦フラグ(省略化)
	 * @param ml 拡大表示オプションフラグ(省略化)
	 */
	changeContent: function(id, ap, lg, au, rc, ml, sc, hq, dt)
	{
		this.pSpotId = id;
		var arg_id = String(id);
		var arg_ap = String(ap);
		var arg_lg = String(lg);
		var arg_au = String(au);
		var arg_rc = String(rc);
		var arg_ml = String(ml);
		var arg_sc = String(sc);
		var arg_hq = String(hq);
		var arg_dt = String(dt);

		if (ap == undefined) arg_ap = this.pAutoPlay;
		if (lg == undefined) arg_lg = this.pLogo;
		if (au == undefined) arg_au = this.pAudio;
		if (rc == undefined) arg_rc = this.pRecommend;
		if (ml == undefined) arg_ml = this.pMediaLink;
		if (sc == undefined) arg_sc = this.pShowCtlConst;
		if (hq == undefined) arg_hq = this.pQuality;
		if (dt == undefined) arg_dt = this.pDisplayType;

		document.getElementById(this.pId).innerHTML = this.getPlayerTag(arg_id, arg_ap, arg_lg, arg_au, arg_rc, arg_ml, arg_sc, arg_hq, arg_dt);
	},

	getPlayerObjectHtml: function(id)
	{
		return this.getPlayerTag(String(id), this.pAutoPlay, this.pLogo, this.pAudio, this.pRecommend, this.pMediaLink, this.pShowCtlConst, this.pQuality, this.pDisplayType);
	},

	getPlayerTag: function(id, ap, lg, au, rc, ml, sc, hq, dt)
	{
		var swf = new jp.catalase.SwfTagWriter(EPCONST.swfPath, "obj_"+this.pId, this.pWidth, this.pHeight);
		swf.setRequiredVersion(9,0,0);
		swf.setAltContent('最新のFlashPlayerをインストールしてください');
		swf.setLoop(false);
		swf.setQuality('high');
		swf.addParam('allowScriptAccess', 'always');
		swf.addParam('scale', 'showall');
		swf.addParam('wmode', 'transparent');
		swf.addFlashVars('dm', EPCONST.domain);
		swf.addFlashVars('id', id);
		swf.addFlashVars('ap', ap);
		swf.addFlashVars('lg', lg);
		swf.addFlashVars('au', au);
		swf.addFlashVars('rc', rc);
		swf.addFlashVars('ml', ml);
		swf.addFlashVars('sc', sc);
		swf.addFlashVars('hq', hq);
		swf.addFlashVars('dt', dt);
		return swf.getHTML();
	},

	/**
	 * 再生中のプレーヤIDを取得する
	 */
	getId: function()
	{
		return this.pId;
	},

	/**
	 * 再生中のスポットIDを取得する
	 */
	getSpotId: function()
	{
		return this.pSpotId;
	},
	
	/**
	 * プレーヤサイズを設定する
	 *
	 * @param width プレーヤ幅
	 * @param height プレーヤ高さ
	 */
	setSize: function(width, height)
	{
		this.pWidth = width;
		this.pHeight = height;
	},
	/**
	 * 自動再生オプションのデフォルト値を設定する
	 *
	 * @param ap 自動再生フラグ(0:OFF、1:ON)
	 */
	setAutoPlayOption: function(ap)
	{
		this.pAutoPlay = String(ap);
	},
	/**
	 * ロゴ表示オプションのデフォルト値を設定する
	 *
	 * @param lg ロゴ表示フラグ(0:OFF、1:ON)
	 */
	setLogoOption: function(lg)
	{
		this.pLogo = String(lg);
	},
	/**
	 * 音声オプションのデフォルト値を設定する
	 *
	 * @param au 音声フラグ(0:OFF、1:ON)
	 */
	setAudioOption: function(au)
	{
		this.pAudio = String(au);
	},
	/**
	 * 推薦オプションのデフォルト値を設定する
	 *
	 * @param rc 推薦フラグ(0:OFF、1:ON)
	 */
	setRecommendOption: function(rc)
	{
		this.pRecommend = String(rc);
	},
	/**
	 * 拡大表示オプションのデフォルト値を設定する
	 *
	 * @param ml 拡大表示オプションフラグ(0:OFF、1:ON)
	 */
	setMediaLinkOption: function(ml)
	{
		this.pMediaLink = String(ml);
	},

	/**
	 * 動画高ビットレートオプション
	 *
	 * @param 0 低ビットレート 1 高ビットレート
	 */
	setQuality: function(hq)
	{
		this.pQuality = String(hq);
	},

	/**
	 * コントロールバー常時表示オプションのデフォルト値を設定する
	 *
	 * @param sc コントロールバー常時表示オプションフラグ(0:OFF、1:ON)
	 */
	setShowCtlConst: function(sc)
	{
		this.pShowCtlConst = String(sc);
	},

	/**
	 * 表示形式
	 * @param dt 表示形式フラグ( 0:旧街ログ動画(4:3)、新街ログ動画(16:9) )
	 */
	setDisplayType: function(dt)
	{
		this.pDisplayType = String(dt);
	},

	setSWFPath: function(path)
	{
		EPCONST.swfPath = path;
	},

	setServicePath: function(path)
	{
		EPCONST.domain = path;
	}

}
