var	cocoList = {
//	---
	Version						:	"0.01g"

//	---
,	category_select			:	'＜カテゴリーを選択＞'
,	h2title					:	'記事タイトル一覧'
,	h3title					:	'■ '
,	pathinfo				:	null
,	onChangeFunction		:	null
,	useCategoryCloud		:	false
,	tgtCategoryCloud		:	'archive-category'
,	useCategoryBacknumber	:	false	// cocoMakeBN.user.js

//	---
,	cat_show_catid	:	0
,	cat_show_start	:	0
,	cat_show_num	:	5

//	---
,	category		:	{
		index			:	new Array()
	,	kind			:	new	Array()
	}

//	---
,	getPathInfo					:	function	() {
		for (;;) {
			if ( cocoList.pathinfo ) break ;
			try {
				var	h1=document.getElementsByTagName('h1')[0];
				if ( h1.getElementsByTagName('a')[0].href.match(/^(http:\/\/.+?\/)([^\/]+)\//) ) {
					cocoList.pathinfo = {
						base_url	:	RegExp.$1
					,	blog_name	:	RegExp.$2
					};
					break;
				}
			}
			catch (e) {
				var	links = document.getElementsByTagName('link') ;
				for ( var ci=0,len=links.length; ci<len; ci++ ) {
					if ( links[ci].title.match(/RSS 1.0/) || links[ci].title== "RSS" ) {	//	2008.10.26: ココログ仕様変更に伴う修正
						if ( links[ci].href.match(/^(http:\/\/.+?\/)([^\/]+)\/index.rdf$/) ) {
							cocoList.pathinfo = {
								base_url	:	RegExp.$1
							,	blog_name	:	RegExp.$2
							} ;
						}
						break ;
					}
				}
			}
			break ;
		}
		return cocoList.pathinfo ;
	}	//	end of getPathInfo()

,	loadScript					:	function( src, charset ) {
		var	ret = false ;
		for (;;) {
			var	callScript = document.createElement("script") ;
			if ( !callScript ) break ;
			
			callScript.type = "text/javascript" ;
			callScript.charset = ( charset ) ? charset : "utf-8" ;
			callScript.src = src + '?ver=' + (new Date).getTime() ;
//			callScript.defer = 'defer' ;
			
			document.body.appendChild( callScript ) ;
			
			ret = true ;
			break ;
		}
		return ret ;
	}	//	end of loadScript()

,	showCategory				:	function( catid, start_no, num ) {
		if ( !catid ) return ;
		if ( !start_no ) start_no = 0 ;
		if ( !num ) num = 5 ;
		cocoList.cat_show_catid = catid ;
		cocoList.cat_show_start = start_no ;
		cocoList.cat_show_num = num ;
		var	pathinfo = cocoList.getPathInfo() ;
		if ( pathinfo ) {
			var	catscript =  pathinfo['base_url'] + 'category/' + pathinfo['blog_name'] + '/category_' + catid + '.js' ;
			cocoList.loadScript(catscript) ;
		}
		else {
			alert( 'showCategory: cannot find path-information on this page' ) ;
		}
	}	//	end of showCategory()

,	showCategoryCloud			:	function() {
		for (;;) {
			if ( !(cocoList.useCategoryCloud) || !(cocoList.category.nums) ) break ;
			var	tgtObj = document.getElementById(cocoList.tgtCategoryCloud) ;
			if ( !tgtObj ) {
				setTimeout( cocoList.showCategoryCloud, 100 ) ;
				break ;
			}
			var	divs = tgtObj.getElementsByTagName('div') ;
			for ( var ci=0,len=divs.length; ci<len; ci++ ) {
				if ( divs[ci].className.match( 'module-body' ) ) {
					tgtObj = divs[ci] ;
					break ;
				}
			}
			var	catlists = new Array() ;
			for ( var catid in cocoList.category.nums ) {
				catlists[catlists.length] = {
					'catid'	:	catid
				,	'num'	:	cocoList.category.nums[catid]
				,	'kind'	:	cocoList.category.index[catid]
				} ;
			}
			catlists.sort(function(x,y){return(x.num-y.num);}) ;
			var	divisor = ( eval(catlists[catlists.length-1].num) + 1 - eval(catlists[0].num) ) / 5 ;
			if ( divisor == 0 ) break ;
			catlists.sort(function(x,y){return((x.kind<y.kind)?(-1):((x.kind>y.kind)?1:0));}) ;
			var	elms = new Array() ;
			for ( var ci=0,len=catlists.length; ci<len; ci++ ) {
				catid = catlists[ci].catid ;
				num = catlists[ci].num ;
				kind = catlists[ci].kind ;
				var	level = Math.floor( num / divisor ) + 1 ;
				if ( 5 < level ) level = 5 ;
				elms[elms.length] = [
					'<a href="javascript:void(0);"'
				,	'title="' + num + '件"'
				,	'onclick="javascript:cocoList.showCategory(\'' + catid  + '\');return false;"'
				,	'class="cocoListCloudLevel' + level + '"'
				,	'>' + kind + '</a>'
				].join(' ') ;
			}
			var	divObj = document.createElement('div') ;
			divObj.className = 'cocoListCloud' ;
			divObj.innerHTML = elms.join(' &nbsp;') ;
			tgtObj.innerHTML = '' ;
			tgtObj.appendChild(divObj) ;
			break ;
		}
	}	//	end of showCategoryCloud()
	
,	loadComplete				:	function( blog_id, kind, kind_id ) {
		switch ( kind ) {
			case	'category_index'	:
				var	links = new Array() ;
				for ( var catid in cocoList.category.index ) {
					links[links.length] = {
						'catid' : catid
					,	'kind' : cocoList.category.index[catid]
					} ;
				}
				links.sort(function(x,y){return((x.kind<y.kind)?(-1):((x.kind>y.kind)?1:0));}) ;
				for ( var ci=0,len=links.length; ci<len; ci++ ) {
					var	catid = links[ci].catid ;
					var	kind = links[ci].kind ;
					var	numstr = ( cocoList.category.nums ) ? ( '(' + cocoList.category.nums[catid] + ')' ) : '' ;
					links[ci] = [
						'<option value="'
					,	catid
					,	'">'
					,	kind + numstr
					,	'</option>'
					].join('') ;
				}
				var	tgtObj = document.getElementById('cocoList-category') ;
				if ( tgtObj ) {
/*
// --- NG on IE6 (from)
//					tgtObj.innerHTML = [
//						'<form name="cocoList-category" class="cocoList-category-form" action="javascript:void(0);">'
//					,	'<select name="cocoList-category-select" onchange="javascript:cocoList.showCategory(this.value);this.options[0].selected=true;">'
//					,	'<option value="" selected>' + cocoList.category_select + '</option>'
//					,	links.join('\n')
//					,	'</select>'
//					,	'</form>'
//					].join('') ;
// --- NG on IE6 ( to )
*/
					var	frmObj = document.createElement('form') ;
					frmObj.name = 'cocoList-category' ;
					frmObj.className = 'cocoList-category-form' ;
					frmObj.action = function() { void(0) } ;
					frmObj.innerHTML = [
						'<select name="cocoList-category-select" onchange="javascript:cocoList.showCategory(this.value);this.options[0].selected=true;">'
					,	'<option value="" selected>' + cocoList.category_select + '</option>'
					,	links.join('\n')
					,	'</select>'
					].join('') ;
					tgtObj.appendChild(frmObj) ;
				}
				setTimeout( cocoList.showCategoryCloud, 0 ) ;
				break ;
			case	'category_data'		:
				var	links = new Array() ;
				var	tmplist = cocoList.category.kind[cocoList.cat_show_catid].list ;
				for ( var ci=0,len=tmplist.length; ci<len; ci++ ) {
					links[ci] = [
						'<tr>'
					,	'<td class="cocoList-catlist-no">' + (ci+1) + '.</td>'
					,	'<td class="cocoList-catlist-date">[20' + tmplist[ci].date + ']&nbsp;</td>'
					,	'<td class="cocoList-catlist-title"><a href="'
					,	tmplist[ci].link
					,	'">'
					,	tmplist[ci].title
					,	'</a></td></tr>'
					].join('') ;
				}
				var	tgtObj = document.getElementById('center') ;
				if ( tgtObj ) {
					var	divs = tgtObj.getElementsByTagName('div') ;
					for ( var ci=0,len=divs.length; ci<len; ci++ ) {
						if ( divs[ci].className == 'content' ) {
							tgtObj = divs[ci] ;
							break ;
						}
					}
					if ( divs.length <= ci ) break ;
					var	numstr = ( cocoList.category.nums ) ? ( '&nbsp;<span class="cocoList-catnum">(全' + cocoList.category.nums[cocoList.cat_show_catid] + '件)</span>' ) : '' ;
					var	pathinfo = cocoList.getPathInfo() ;
					var	h3title = [
						cocoList.h3title
					,	(cocoList.useCategoryBacknumber)?'<a href="/'+pathinfo['blog_name']+'/backnumbers/cat'+kind_id+'/bnlast.html" title="backnumbers">':''
					,	cocoList.category.kind[cocoList.cat_show_catid].name
					,	(cocoList.useCategoryBacknumber)?'<\/a>':''
					,	numstr
					].join('');
					tgtObj.innerHTML = [
						'<h2>' + cocoList.h2title + '</h2>'
					,	'<div class="entry-top"></div>'
					,	'<div class="entry">'
					,	'<h3>' + h3title + '</h3>'
					,	'<a id="cat' + kind_id + '"></a>'
					,	'<div class="entry-body-top"></div>'
					,	'<div class="entry-body">'
					,	'<div class="entry-body-text">'
					,	'<table class="cocoList-catlist"><tbody>'
					,	links.join('\n')
					,	'</tbody></table>'
					,	'</div><!-- class="entry-body-text" -->'
					,	'</div><!-- class="entry-body" -->'
					,	'<p class="posted"></p>'
					,	'<div class="entry-body-bottom"></div>'
					,	'</div><!-- class="entry" -->'
					,	'<div class="entry-bottom"></div>'
					].join('') ;
					// --- for 'cocoQLink.js'
					if ( typeof makeQuickLink == "function" ) makeQuickLink( tgtObj ) ;
//					setTimeout( 'location.hash="cat' + kind_id + '"', 100 ) ;
//					setTimeout( 'window.scrollTo(0,0)', 0 ) ;
					window.scrollTo(0,0) ;
					if ( typeof cocoList.onChangeFunction == 'function' ) {
						cocoList.onChangeFunction() ;
					}
				}
				break ;
			default						:
				break ;
		}
	}	//	end of loadComplete()

,	init						:	function() {
		var	pathinfo = cocoList.getPathInfo() ;
		if ( pathinfo ) {
			var	catscript =  pathinfo['base_url'] + 'category/' + pathinfo['blog_name'] + '/category_index.js' ;
//			cocoList.loadScript(catscript) ;
			document.write( '<script type="text/javascript" src="' + catscript + '"></script>' ) ;
		}
		else {
			alert( 'showCategory: cannot find path-information on this page' ) ;
		}
	}	//	end of init()
	
}	//	end of cocoList Object
