document.addEventListener("DOMContentLoaded",function(){setTimeout(function(){
	if(typeof window.WatchApp.namespace.model.player.NicoPlayerConnector.playerAreaConnector==='undefined')return setTimeout(arguments.callee,500);
	
	window.WatchApp.namespace.model.player.NicoPlayerConnector.playerAreaConnector.addEventListener("onVideoInitialized",function(){setTimeout(nlCommonsTree.comTree(),0)});
},0)},false);
var nlCommonsTree={
	comTree:function(){
		var T=this
		T.HttpRequest(
			'/pr_Redirect_api.commons.nicovideo.jp/tree/summary/get?id='+window.WatchApp.namespace.model.player.NicoPlayerConnector.watchInfoModel.id+'&limit=100&callback=callback',
			function(R){
				var callback=T.TreeAPICallback;
				eval(R.responseText);
			},
			true
		)
	},
	TreeAPICallback:function(X){
		const D=document;
		var cParent=X.countparent-0,
			cChild =X.countchild-0;
		if(!(cParent||cChild)){
			if(!D.getElementById('nl_itab_tree')){
				return;
			}else{
				var E=D.getElementById('nl_itab_tree');
				E.parentNode.removeChild(E);
				(E=D.getElementsByClassName('tree')[0]).parentNode.removeChild(E);
				return;
			}
		}
		var E=(cParent?'[親]'+cParent:'')+(cChild?'[子]'+cChild:''),
			elem=['<a href="http://commons.nicovideo.jp/tree/'+window.WatchApp.namespace.model.player.NicoPlayerConnector.watchInfoModel.id+'" style="display:block;color:black;text-align:center;">ニコニコモンズで確認</a>'],
			parent=X.parent;
		if(!D.getElementById('nl_itab_tree')){
			D.getElementById('nl_itab').insertAdjacentHTML("BeforeEnd",'<a href="javascript:void(0)" id="nl_itab_tree" onClick="nl_itab(\'tree\')">コンテンツツリー '+E+'</a>')
			D.getElementById('nl_itab_Frame').insertAdjacentHTML("BeforeEnd",'\r\n\t<div class="tree" style="display:none"></div>');
		}else{
			D.getElementById('nl_itab_tree').textContent='コンテンツツリー '+E;
		}
		for(var i=parent.length;i--;){
			var p=parent[i];
			elem.unshift(
				'<table class="treeFlame">'+
					'<tr>'+
						'<td rowspan="2"><a href="'+p.url+'" class="left"><img src="'+p.thumbnail+'" /></a></td>'+
						'<td>'+p.registered_date+'にツリー登録</td>'+
					'</tr>'+
					'<tr><td><a href="'+p.url+'" onMouseOver="return popThumb2(\''+p.parentid+'\', 0)" onMouseOut="return nd()">'+p.title+'</a></td></tr>'+
				'</table>');
		}
		D.getElementsByClassName('tree')[0].innerHTML=elem.join('');
	},
	HttpRequest:function(url,func,Async,h){
		var httpObj=new XMLHttpRequest(),R='';
		httpObj.abort();
		httpObj.open('GET',url,!!Async);
		httpObj.setRequestHeader('If-Modified-Since','Thu, 01 Jun 1970 00:00:00 GMT');
		httpObj.onload=function(){if(typeof func=='function')R=func(httpObj,h)}
		httpObj.send(null);
		return R;
	}
}