var	cocoCatTree = {
//	---
	Version						:	"0.01"
//	---
,	reverse						:	false
,	onload						:	null
//	---
,	xmlnsRdf					:	'http://www.w3.org/1999/02/22-rdf-syntax-ns#'
,	xmlnsDc						:	'http://purl.org/dc/elements/1.1/'
//	---
,	catId						:	'archive-category'
//	---
,	entryList						:	[]
//	---
,	getNodeText					:	(
		function ( node ) {
			return ( ( node.hasChildNodes() ) ? node.childNodes[0].nodeValue : "" ) ;
		}
	)	//	end of getNodeText()
//	---
,	makeTree					:	(
		function ( entryList ) {
			var	catList = document.getElementById(this.catId) ;
			if ( !catList ) return ;
			
			var	lists = catList.getElementsByTagName('li') ;
			for ( var ci=0; ci < lists.length; ci++ ) {
				if ( lists[ci].className == 'lst' || lists[ci].className == 'end' ) continue ;
				var	links = lists[ci].getElementsByTagName('a') ;
				if ( links.length != 1 ) continue ;
				var	cat = links[0].innerHTML ;
				var	entryInfos = entryList[cat] ;
				if ( !entryInfos || entryInfos.length < 1 ) continue ;
				var	listHtml = '<ul class="tree">' ;
				var cj ;
				if ( this.reverse ) {
					for ( cj=entryInfos.length-1; 0 < cj; cj-- ) {
						listHtml += '<li class="lst"><a href="' + entryInfos[cj].link +'">' + entryInfos[cj].title + '</a></li>' ;
					}
				}
				else {
					for ( cj=0; cj < entryInfos.length-1; cj++ ) {
						listHtml += '<li class="lst"><a href="' + entryInfos[cj].link +'">' + entryInfos[cj].title + '</a></li>' ;
					}
				}
				listHtml += '<li class="end"><a href="' + entryInfos[cj].link +'">' + entryInfos[cj].title + '</a></li>' ;
				listHtml += '</ul>' ;
				lists[ci].innerHTML += listHtml ;
			}
			if ( typeof this.onload == 'function' ) {
				this.onload() ;
			}
		}
	)	//	end of makeTree()
//	---
,	checkRss					:	(
		function	( rsp ) {
			var	indexRdf = rsp.responseXML ;
			
			var	items = indexRdf.getElementsByTagName('item') ;
			
			var	entryList = this.entryList ;
			
			for ( var ci=0; ci < items.length; ci++ ) {
				var	title = this.getNodeText( items[ci].getElementsByTagName('title')[0] ) ;
				var	link = this.getNodeText( items[ci].getElementsByTagName('link')[0] ) ;
				if ( navigator.userAgent.toLowerCase().match( /msie/i ) ) {	//	for IE
					var	cats = items[ci].getElementsByTagName('dc:subject')
				}
				else {
					var	cats = items[ci].getElementsByTagNameNS( this.xmlnsDc, 'subject' ) ;
				}
				for ( var cj=0; cj < cats.length; cj++ ) {
					var	cat = this.getNodeText( cats[cj] ) ;
					if ( !entryList[cat] ) entryList[cat] = [] ;
					var	num = entryList[cat].length ;
					if ( !entryList[cat][num] ) entryList[cat][num] = [] ;
					entryList[cat][num].title = title ;
					entryList[cat][num].link = link ;
				}
			}
			this.makeTree( entryList ) ;
		}
	)	//	end of checkRss()
//	---
,	loadRssRequest				:	(
		function	() {
			var	links = document.getElementsByTagName('link') ;
			var	ci ;
			for ( ci=0; ci < links.length; ci++ ) {
				if ( links[ci].title.match(/RSS 1.0/) || links[ci].title== "RSS" ) break;	//	2008.10.26: ココログ仕様変更に伴う修正
			}
			if ( ci < links.length ) {
				new Ajax.Request( links[ci].href, {method: 'get', onComplete: function(rsp){ cocoCatTree.checkRss(rsp); } } );    
			}
			else {
				alert( "cocoCatTree.js: RSSが見付かりません" ) ;
			}
		}
	)	//	end of loadRssRequest()
//	---
,	init						:	(
		function	()	{
			for (;;) {
				this.loadRssRequest() ;
				break ;
			}
		}
	)	//	end of init()
	
}	//	end of cocoCatTree object

//	cocoCatTree.init() ;
