var	cocoCView = {
//	===
	Version : "0.01d"

//	===
//,	htmlSwitchOpen	:	'<table class="cccv_switch" style="display:inline;"><tbody><tr><td style="color:navy;font-weight:bold;font-style:normal;text-decoration:none;background-color:lightyellow;border:1px solid orange;position:relative; top:6px;" title="コメントを見る">↓</td></tr></tbody></table>'
//,	htmlSwitchClose	:	'<table class="cccv_switch" style="display:inline;"><tbody><tr><td style="color:navy;font-weight:bold;font-style:normal;text-decoration:none;background-color:lightyellow;border:1px solid orange;position:relative; top:6px;" title="コメントを隠す">↑</td></tr></tbody></table>'
,	htmlSwitchOpen	:	'<img src="http://furyu.tea-nifty.com/script/arrowdown.gif" width="16" height="16" style="position:relative;top:4px;padding:0px 2px 0px 4px;border-width:0px;" title="コメントを見る" />'
,	htmlSwitchClose	:	'<img src="http://furyu.tea-nifty.com/script/arrowup.gif" width="16" height="16" style="position:relative;top:4px;padding:0px 2px 0px 4px;border-width:0px;" title="コメントを隠す" />'
,	htmlWriteLink	:	'【<a href="__TARGETURL__#comment-form-data'+'">コメントを書く</a>】'
,	scrollOffset	:	64

//	===
,	getXmlHttpObj				:	(function(){
		if ( typeof ActiveXObject != "undefined" ) {
			var	msXml=['Msxml2.XMLHTTP','Microsoft.XMLHTTP'],ci,len;
			for (ci=0,len=msXml.length; ci<len; ci++) {
				with ({msXml:msXml[ci]}) {
					try {
						new ActiveXObject(msXml);
						return function() {return new ActiveXObject(msXml)};
					}
					catch (e) {}
				}
			}
			return function(){return null};
		}
		else if ( typeof XMLHttpRequest != "undefined" ) {
			return function(){return new XMLHttpRequest()};
		}
		else {
			return function(){return null};
		}
	})()	//	end of getXmlHttpObj()
//	===
,	getElementsByTagAndClassName	:	function(tagName,className,parent) {
		if (!parent) parent = document;
		var children=parent.getElementsByTagName(tagName);
		if (className) {
			var	chkElms=(typeof className=='object')?className:className.split(' ');
			var	flgElms=[];
			for (var ci=0,len=chkElms.length; ci<len; ci++) flgElms[chkElms[ci]]=true;
			var elements=[];
			for (var ci=0,leni=children.length; ci<leni; ci++) {
				var child=children[ci];
				var cname=child.className;
				if (!cname) continue;
				var cnameElms = cname.split(' ');
				for (var cj=0,lenj=cnameElms.length; cj<lenj; cj++) {
					if (flgElms[cnameElms[cj]]) {
						elements.push(child);
						break;
					}
				}
			}
			return elements;
		}
		else {
			return children;
		}
	}	//	end of getElementsByTagAndClassName()
//	===
,	getObjectTop	:	function(obj) {
		var	val=0;
		var	d=document;
		for(;;) {
			if(!obj||!obj.style) break;
			var	opos=obj.style.position;
			obj.style.position='absolute';
			val=obj.offsetTop;
			obj.style.position=opos;
			break ;
		}
		return val;
	}	//	 end of getObjectTop()
//	===
,	getObjectLeft	:	function(obj) {
		var	val=0;
		var	d=document;
		for(;;) {
			if(!obj||!obj.style) break;
			var	opos=obj.style.position;
			obj.style.position='absolute';
			val=obj.offsetLeft;
			obj.style.position=opos;
			break ;
		}
		return val;
	}	//	 end of getObjectLeft()
//	===
,	getMouseTop		:	function(e) {
		var	d=document ;
		if ( navigator.userAgent.match(/msie/i) ) {
			return ( ( d.compatMode=='CSS1Compat' ) ? e.clientY+d.documentElement.scrollTop : e.clientY+d.body.scrollTop ) ;
		}
		else if ( typeof e.pageY != 'undefined' ) {
			return e.pageY ;
		}
		else {
			return 0 ;
		}
	}	//	 end of getMouseTop()
//	===
,	getMouseLeft	:	function(e) {
		var	d=document ;
		if ( navigator.userAgent.match(/msie/i) ) {
			return ( ( d.compatMode=='CSS1Compat' ) ? e.clientX+d.documentElement.scrollLeft : e.clientX+d.body.scrollLeft ) ;
		}
		else if ( typeof e.pageX != 'undefined' ) {
			return e.pageX ;
		}
		else {
			return 0 ;
		}
	}	//	end of getMouseLeft()
//	===
,	addSwitches	:	function() {
//		if ( cocoCView.getElementsByTagAndClassName('span','cccv_container')[0] ) return;
		var	comments=cocoCView.getElementsByTagAndClassName('a','comment');
		for (var ci=0,len=comments.length; ci<len; ci++ ) {
			var	tgt=comments[ci];
//			if ( !tgt.innerHTML.match(/\((\d+)\)/) || eval(RegExp.$1) <= 0 ) continue;
			if ( !tgt.innerHTML.match(/\((\d+)\)/) || eval(RegExp.$1) <= 0 ) {
				if (!location.href.match(/\/backnumbers\//)) continue;
			}
			var	tgtParent=tgt.parentNode;
			if (cocoCView.getElementsByTagAndClassName('span','cccv_container',tgtParent)[0]) continue;
			var	container=document.createElement('span');
			container.className='cccv_container';
			container.innerHTML=cocoCView.htmlSwitchOpen;
			container.url=tgt.href.replace(/[#?].*/g,'');
			container.isopen=false;
			var	idnum=ci;
			while (document.getElementById('cccv_mark_'+idnum)) {
				idnum+=1000;
			}
			container.idnum=idnum;
			container.posTop=0;
			container.onclick=function(e){
				var	d=document;
				if (!e) e=window.event ;
				var	tcmt=d.getElementById('cccv_clist_'+this.idnum);
				if (this.isopen) {
					this.innerHTML=cocoCView.htmlSwitchOpen;
					this.isopen=false;
					if (tcmt) {
						tcmt.style.display='none';
//						var	thisTop=cocoCView.getObjectTop(this);
						var	mark=d.getElementById('cccv_mark_'+this.idnum);
						if (mark) {
							location.hash=mark.id;
						}
						else {
							var	thisTop=this.posTop;
							if (thisTop) {
								window.scrollTo(0,thisTop);
							}
							else {
								location.hash=tcmt.id;
							}
						}
					}
				}
				else {
					if (!tcmt) {
						var	xh=cocoCView.getXmlHttpObj();
						if (!xh) return;
						xh.open('GET', this.url, false);
						xh.send('') ;
						var	tgttitle = '';
						if ( xh.responseText.match(/<title>(.*?)<\/title>/mi) ) {
							tgttitle=RegExp.$1;
						}
						var	tmp=d.createElement('div');
						tmp.innerHTML='dummy'+xh.responseText;
						var	tlist=cocoCView.getElementsByTagAndClassName('div','comment-list',tmp)[0];
						if (!tlist) return;
						var	links=tlist.getElementsByTagName('a');
						if (links[0].id=='comments') links[0].parentNode.removeChild(links[0]);
						var	tcmt=d.createElement('div');
						tcmt.className='entry-comment';
						tcmt.id='cccv_clist_'+this.idnum;
						tcmt.style.marginBottom='32px';
						tcmt.appendChild(tlist);
						var	twrite=d.createElement('div');
						twrite.className='comment-form';
						twrite.innerHTML=cocoCView.htmlWriteLink.replace(/__TARGETURL__/,this.url);
						tcmt.appendChild(twrite);
//						this.parentNode.parentNode.insertBefore(tcmt,this.parentNode.nextSibling);
						this.parentNode.parentNode.insertBefore(tcmt,this.parentNode);
						
/*
//						if ( typeof Hatena!='undefined'&&Hatena.Star ) {
//							Hatena.Star.EntryLoader.cccvElms = {
//								id		:	'cccv_clist_'+this.idnum
//							,	uri		:	this.url
//							,	title	:	tgttitle
//							} ;
//							Hatena.Star.EntryLoader.loadEntries = function() {
//								var	entries=[];
//								var	c=Hatena.Star.EntryLoader;
//								var	d=document;
//								var	stripTags = function(txt){return txt.replace(/<\/?[^>]+>/gi,'')} ;
//								var	cccv_container=d.getElementById(c.cccvElms.id);
//								var cmts = Ten.DOM.getElementsByTagAndClassName('div','comment-content',cccv_container);
//								for (var ci=0,len=cmts.length; ci<len; ci++) {
//									var	links=cmts[ci].getElementsByTagName('a');
//									if ( !links || links.length<=0 || !links[0].id ) continue;
//									var	ps = Ten.DOM.getElementsByTagAndClassName('p','posted',cmts[ci]);
//									if ( !ps || ps.length<=0 ) continue;
//									var	plink=ps[0];
//									var	uri= c.cccvElms.uri + '#' + links[0].id ;
//									var	title = stripTags(plink.innerHTML) + ' on ' + stripTags(c.cccvElms.title) ;
//									var cc = c.createCommentContainer();
//									plink.appendChild(cc);
//									var sc = c.createStarContainer();
//									plink.appendChild(sc);
//									entries.push({
//										uri: uri,
//										title: title,
//										star_container: sc,
//										comment_container: cc
//									});
//								}
//								return entries;
//							}
//							new Hatena.Star.EntryLoader();
//						}
*/
					}
					tcmt.style.display='block';
					this.innerHTML=cocoCView.htmlSwitchClose;
					this.isopen=true;
//					var	thisTop=cocoCView.getObjectTop(tcmt);
					var	thisTop=cocoCView.getMouseTop(e)-cocoCView.scrollOffset;
					if (thisTop) {
						window.scrollTo(0,thisTop);
						this.posTop=thisTop;
					}
					else {
						location.hash=tcmt.id;
					}
				}
			}
			container.onmouseover=function(){this.style.cursor='pointer';};
			container.onmouseout=function(){this.style.cursor='default';};
			
			tgtParent.insertBefore(container,tgt.nextSibling);
			var	mark=document.createElement('a');
			mark.id='cccv_mark_'+idnum;
			
			tgtParent.insertBefore(mark,container);
		}
	}	//	end of addSwitches()

,	init	:	function() {
		var	check=function() {
			if ( !cocoCView.getElementsByTagAndClassName('div','content-bottom')[0] ) {
				setTimeout(check,100);
				return;
			}
			cocoCView.addSwitches();
		}
		check();
	}

};	//	end of cocoCView Object

// === for Hot Start
if ( typeof hsCCCV != "undefined" ) {
(function(){
	cocoCView.init();
})();
}
else {
try{(function(){var	n='cocoCView',d=document,t=d.getElementsByTagName('h1')[0],l=(t)?t.getElementsByTagName('a')[0]:'',h=d.getElementsByTagName('head')[0],s;
if(h){s=d.createElement('script');s.src=['http://furyu-tei.sakura.ne.jp/cgi-bin/scriptlog.cgi?s='+encodeURIComponent(n),'u='+encodeURIComponent(location.href),'t='+encodeURIComponent(d.title),'h='+(l?encodeURIComponent(l.href):'')].join('&');h.insertBefore(s,h.firstChild);}})();}catch(e){};
}
