document.addEventListener("DOMContentLoaded",function(){setTimeout(function(){
const	scale_M_def  =1.00000/* 中画面サイズ拡大倍率 */
		,margin_M_def=0      /* 中画面サイズ位置調整(マイナス指定で左に移動、単位はpx) */
		,scale_N_def =1.33630/* 大画面サイズ拡大倍率(倍率基準は中画面サイズ,デフォルト1.33630) */
		,margin_N_def=0      /* 大画面サイズ位置調整(マイナス指定で左に移動、単位はpx) */
		,space_def   =10     /* #playerNicoplayer <> #playerTabWrapper間のスペース(デフォルト10[px]) */
		,EnableExtendCommentLogMode_M=false/* 中画面でExtendCommentLogサイズを考慮する */
		,EnableExtendCommentLogMode_N=false/* 大画面でExtendCommentLogサイズを考慮する */
		,EnableExtendCommentLogMode  =false/* 中画面拡大倍率を大画面基準にしてExtendCommentLogを考慮する */
		,decimal=5/* 小数点以下有効桁数 */
		/* ---------------------- */
		,D=document
		,qS=function(e){return D.querySelector(e)}
		,getStyle=function(e,s){return D.defaultView.getComputedStyle(qS(e),'').getPropertyValue(s)}
		,Fd=function(V){var _V=Math.pow(10,decimal);return ((V*_V)|0)/_V};
		//,Fd=function(V){return ((V+"").slice(0,(V+"").indexOf('.')+(_decimal+1)))-0}

var scale_M=scale_M_def,margin_M=margin_M_def
	,scale_N=scale_N_def,margin_M=margin_M_def
	,space=space_def
	,ECLMode_M=EnableExtendCommentLogMode_M
	,ECLMode_N=EnableExtendCommentLogMode_N
	,ECLMode=EnableExtendCommentLogMode
if(window.SettingUtil_pr_nl){
	var su=SettingUtil_pr_nl.getInstance("nlPlayerResize");
	if(su.IsEnabled){
		scale_M  =su.getSetting("scale_medium",scale_M_def);
		margin_M =su.getSetting("margin_medium",margin_M_def);
		scale_N  =su.getSetting("scale_normal",scale_N_def);
		margin_N =su.getSetting("margin_normal",margin_N_def);
		space    =su.getSetting("space",space_def);
		ECLMode_M=su.getSetting("ECLMode_M",EnableExtendCommentLogMode_M);
		ECLMode_N=su.getSetting("ECLMode_N",EnableExtendCommentLogMode_N);
		ECLMode  =su.getSetting("ECLMode",EnableExtendCommentLogMode);
	}
}
/**/
(function(){
	var V=qS('#playerTabContainer').classList;
	if(V.contains('has_panel_ads')){
		V.remove('has_panel_ads');
	}else{
		return setTimeout(arguments.callee,1000);
	}
})();

var V=qS('#playerAlignmentArea').classList,V2=0,playerNicoplayer_W_N;
if(V.contains('size_normal')){
	playerNicoplayer_W_N=getStyle('#playerNicoplayer','width');
	V2=1,V.remove('size_normal'),V.add('size_medium');
}else{
	V.remove('size_medium'),V.add('size_normal');
	playerNicoplayer_W_N=getStyle('#playerNicoplayer','width')
	V.remove('size_normal'),V.add('size_medium');
}
qS('.player-tab-content').style.setProperty('bottom', '0','');
/**/
var O=	{playerContainer_H    :getStyle('#playerContainer','height')
		,playerNicoplayer_W   :getStyle('#playerNicoplayer','width')
		,playerNicoplayer_W_N :playerNicoplayer_W_N
		,playerTabWrapper_W   :getStyle('#playerTabWrapper','width')
		,playerTabWrapper_H   :getStyle('#playerTabWrapper','height')
		,nicoplayerContainer_W:getStyle('#nicoplayerContainer','width')
		,nicoplayerContainer_H:getStyle('#nicoplayerContainer','height')
		,external_nicoplayer_W:getStyle('#external_nicoplayer','width')
		,external_nicoplayer_H:getStyle('#external_nicoplayer','height')
		,textMarquee_iH       :qS('#textMarquee').clientHeight+'px'
		,panelBody_H          :getStyle('.panel-body','height')
		,playerTabContainer_W :getStyle('#playerTabContainer','width')
		,_playerTabContainer_W:getStyle('#playerTabContainer','width')
		,scale_M              :scale_M
		,margin_M             :margin_M
		,scale_N              :scale_N
		,margin_N             :margin_N
		,space                :space
		,ECLMode_M            :EnableExtendCommentLogMode_M
		,ECLMode_N            :EnableExtendCommentLogMode_N
		,ECLMode              :EnableExtendCommentLogMode};
/* CSS埋め込み用div */
D.body.insertAdjacentHTML("BeforeEnd",'<div id="nlPlayerResizeCSS"></div>');
/*--------------------------------------*/
if(V2)V.remove('size_medium'),V.add('size_normal');
/*--------------------------------------*/
var F=function(V){setTimeout(function(){
	var playerContainer_H     =V.playerContainer_H
		,playerNicoplayer_W   =V.playerNicoplayer_W
		,playerNicoplayer_W_N =V.playerNicoplayer_W_N
		,playerTabWrapper_W   =V.playerTabWrapper_W
		,playerTabWrapper_H   =V.playerTabWrapper_H
		,nicoplayerContainer_W=V.nicoplayerContainer_W
		,nicoplayerContainer_H=V.nicoplayerContainer_H
		,external_nicoplayer_W=V.external_nicoplayer_W
		,external_nicoplayer_H=V.external_nicoplayer_H
		,textMarquee_iH       =V.textMarquee_iH
		,panelBody_H          =V.panelBody_H
		,playerTabContainer_W =V.playerTabContainer_W
		,_playerTabContainer_W=V._playerTabContainer_W
		,scale_M              =V.scale_M
		,margin_M             =V.margin_M
		,scale_N              =V.scale_N
		,margin_N             =V.margin_N
		,space                =V.space
		,HEIGHT_M='(('+playerContainer_H+' - '+textMarquee_iH+') * '+scale_M+') + '+textMarquee_iH
		,HEIGHT_N='(('+playerContainer_H+' - '+textMarquee_iH+') * '+scale_N+') + '+textMarquee_iH;
qS('#nlPlayerResizeCSS').innerHTML='<style type="text/css">\
.playerTabAds,.nicoSpotAds,.socialButtons\r\n\
{display:none !important;}\r\n\
\r\n\
body:not(.full_with_browser):not(.size_small) #nicoplayerContainerInner{\r\n\
 top:0 !important;\r\n\
}\r\n\
\r\n\
body.size_medium:not(.full_with_browser) #playerAlignmentArea > #playerContainer{\r\n\
	height:calc('+HEIGHT_M+') !important;\r\n\
	width:calc('+playerNicoplayer_W+' * '+scale_M+' + '+playerTabWrapper_W+' + '+space+'px) !important;\r\n\
	margin-left:calc(((('+playerNicoplayer_W+' + '+playerTabWrapper_W+' + '+space+'px) - ('+playerNicoplayer_W+' * '+scale_M+' + '+playerTabWrapper_W+' + '+space+'px)) / 2) + '+margin_M+'px) !important;\r\n\
}\r\n\
body.size_medium:not(.full_with_browser) #nicoplayerContainer\r\n\
,body.size_medium:not(.full_with_browser) #textMarquee {\r\n\
 width:calc('+nicoplayerContainer_W+' * '+scale_M+') !important;\r\n\
}\r\n\
body.size_medium:not(.full_with_browser) #nicoplayerContainer {\r\n\
 height:calc('+nicoplayerContainer_H+' * '+scale_M+') !important;\r\n\
}\r\n\
body.size_medium:not(.full_with_browser) #external_nicoplayer {\r\n\
 width:calc('+external_nicoplayer_W+' * '+scale_M+') !important;\r\n\
 height:calc('+external_nicoplayer_H+' * '+scale_M+') !important;\r\n\
}\r\n\
body.size_medium #playerTabWrapper{\r\n\
 height:calc('+HEIGHT_M+') !important;\r\n\
}\r\n\
body.size_medium .slick-viewport{\r\n\
 height:calc(('+HEIGHT_M+') - ('+playerTabWrapper_H+' - ('+panelBody_H+' - 24px))) !important;\r\n\
}\r\n\
\r\n\
body.size_normal:not(.full_with_browser) #playerAlignmentArea > #playerContainer{\r\n\
	height:calc('+HEIGHT_N+') !important;\r\n\
	width:calc('+playerNicoplayer_W+' * '+scale_N+' + '+playerTabWrapper_W+' + '+space+'px) !important;\r\n\
	margin-left:calc(((('+playerNicoplayer_W+' + '+playerTabWrapper_W+' + '+space+'px) - ('+playerNicoplayer_W+' * '+scale_N+' + '+playerTabWrapper_W+' + '+space+'px) + ('+playerNicoplayer_W_N+' - '+playerNicoplayer_W+')) / 2) + '+margin_N+'px) !important;\r\n\
}\r\n\
body.size_normal:not(.full_with_browser) #nicoplayerContainer\r\n\
,body.size_normal:not(.full_with_browser) #textMarquee {\r\n\
 width:calc('+nicoplayerContainer_W+' * '+scale_N+') !important;\r\n\
}\r\n\
body.size_normal:not(.full_with_browser) #nicoplayerContainer {\r\n\
 height:calc('+nicoplayerContainer_H+' * '+scale_N+') !important;\r\n\
}\r\n\
body.size_normal:not(.full_with_browser) #external_nicoplayer {\r\n\
 width:calc('+external_nicoplayer_W+' * '+scale_N+') !important;\r\n\
 height:calc('+external_nicoplayer_H+' * '+scale_N+') !important;\r\n\
}\r\n\
body.size_normal #playerTabWrapper{\r\n\
 height:calc('+HEIGHT_N+') !important;\r\n\
}\r\n\
body.size_normal .slick-viewport{\r\n\
 height:calc(('+HEIGHT_N+') - ('+playerTabWrapper_H+' - ('+panelBody_H+' - 24px))) !important;\r\n\
}\r\n\
</style>';
},0)};
/*--------------------------------------*/
F(O);
/**/
var O2={sm:1,mm:2,sn:4,mn:8,flag:0}
	,F1=function(){setTimeout(function(){
		var su =SettingUtil_pr_nl.getInstance("nlPlayerResize")
			,F1=function(V){return V.slice(0,-2)-0}
			,V1=(((F1(O.playerNicoplayer_W) * O.scale_N) + F1(O.playerTabWrapper_W)) - F1(O.playerTabContainer_W)) / F1(O.playerNicoplayer_W)
			,V2=-(F1(O.playerTabContainer_W) - F1(O._playerTabContainer_W)) / 2
		if(O.ECLMode){
			O.scale_M=V1;
			O2.flag|=O2.sm;
			su.setSetting("scale_medium",Fd(V1));
		}
		if(O.ECLMode_M){
			O.margin_M=V2;
			O2.flag|=O2.mm;
			su.setSetting("margin_medium",V2);
		}
		if(O.ECLMode_N){
			O.margin_N=V2;
			O2.flag|=O2.mn;
			su.setSetting("margin_normal",V2);
		}
		F(O);
	},0)}
	,target=qS('#playerTabContainer')
	,config={attributes:true,attributeOldValue:true,attributeFilter:['style']}
	,observer=new MutationObserver(function(mutations){
		for(var i=mutations.length,E;i--;){
			if((E=mutations[i]).type=="attributes"){
				setTimeout(function(){
					if(E.oldValue!=E.target.getAttribute(E.attributeName)){
						O.playerTabContainer_W=E.target.style.getPropertyValue('width');
						if(O.ECLMode || O.ECLMode_M || O.ECLMode_N) F1();
						else F(O);
					}
				},0)
			}
		}
	});
observer.observe(target,config);
/************	↓設定画面の作成↓	************/
if(window.NicoGinza_extendSettingPanel){
	setTimeout(function(){
		if (typeof require("watchapp/init/PlayerInitializer").playerSettingViewController==="undefined"
		||typeof require("watchapp/init/PlayerInitializer").playerSettingViewController.$selector==="undefined")return setTimeout(arguments.callee,1000);
		var esp=new NicoGinza_extendSettingPanel("nlPlayerResize","拡大縮小","プレイヤーを任意倍率に拡大縮小")
			,su=SettingUtil_pr_nl.getInstance("nlPlayerResize");
		if(esp.IsEnabled){
			esp.start_SettingUtil_pr_nl();
			esp.addElement('<p id="nlPR_sm">● 中画面サイズ拡大倍率</p>');
			esp.addSettingElementTextbox("scale_medium",scale_M,"倍",5,function(V){
			if(O2.flag && (O2.flag&O2.sm)){O2.flag&=~O2.sm;return;}
			if((V+'').split('.')[1].length > decimal){
				su.setSetting("scale_medium",Fd(V));
			}else{
				O.scale_M=V;
				F(O);
			}
			});
			esp.addElement('<p id="nlPR_mm">・中画面位置調整(マイナス指定で左に移動)</p>');
			esp.addSettingElementTextbox("margin_medium",margin_M,"px",5,function(V){
				if(O2.flag && (O2.flag&O2.mm)){O2.flag&=~O2.mm;return;}
				O.margin_M=V;
				F(O);
			});
			esp.addSettingElementCheckbox("ECLMode_M",ECLMode_M,"ExtendCommentLogサイズを考慮する",function(V){
				if(O.ECLMode_M && V)return;
				O.ECLMode_M=V;
				if(V)F1();
			});
			esp.addSettingElementCheckbox("ECLMode",ECLMode,"拡大倍率を大画面基準にしてExtendCommentLogを考慮する",function(V){
				O.ECLMode=V;
				if(V){
					O.ECLMode_M=true;
					O.margin_N=0;
					O.ECLMode_N=false;
					F1();
					O2.flag|=O2.mn;
					su.setSetting("ECLMode_M",true);
					su.setSetting("margin_normal",0);
					su.setSetting("ECLMode_N",false);
				};
			});
			esp.addElement('<div style="margin-bottom:0.5em; border-bottom:1px solid gray;"></div>');
			esp.addElement('<p id="nlPR_sn">● 大画面サイズ拡大倍率</p>');
			esp.addSettingElementTextbox("scale_normal",scale_N,"倍",5,function(V){
			if((V+'').split('.')[1].length > decimal){
				su.setSetting("scale_normal",Fd(V));
			}else{
				O.scale_N=V;
				O.ECLMode ?F1() :F(O);
			}
			});
			esp.addElement('<p id="nlPR_mn">・大画面位置調整(マイナス指定で左に移動)</p>');
			esp.addSettingElementTextbox("margin_normal",margin_N,"px",5,function(V){
				if(O2.flag && (O2.flag&O2.mn)){O2.flag&=~O2.mn;return;}
				O.margin_N=V;
				F(O);
			});
			esp.addSettingElementCheckbox("ECLMode_N",ECLMode_N,"ExtendCommentLogサイズを考慮する",function(V){O.ECLMode_N=V;if(V)F1();});
			esp.addElement('<div style="margin-bottom:0.5em; border-bottom:1px solid gray;"></div>');
			esp.addElement('<p>● #playerNicoplayer <> #playerTabWrapper間のスペース(デフォルト10px)</p>');
			esp.addSettingElementTextbox("space",space,"px",5,function(V){O.space=V;F(O);});
		}
	},1000);
}
/************	↑設定画面の作成↑	************/
},1000)},false);