/*==============================================================================
	iBlog のための Recent Comments クラス

	$Id$
	Copyright (C) 2005 OKAMURA Yuji, All rights reserved.
==============================================================================*/
/*---- 静的属性 ----*/

/*---- 静的メソッド ----*/
/*
 * iBlog のための Haloscan による Recent Comments クラス<br>
 * @param url	RSS の URL,
 * @param welmt	RSS Feed を書き出す HTML の DOM ノード
 * @param async	非同期で動作させるかどうか(オプション)
 * @param blogBaseUrl	ブログのベース URL
 */
function CRCHalo4iBlog(url, welmt, async, blogBaseUrl) {
	/*---- 基底クラスのコンストラクタ ----*/
	this.CRCHalo = CRCHalo;
	this.CRCHalo(url, welmt, async);

	/*---- メンバー変数 ----*/
	/*
	 * ブログのベース URL
	 */
	this.m_BlogBaseURL = blogBaseUrl;
	if (!this.m_BlogBaseURL.match(/\/$/)) {
		this.m_BlogBaseURL += '/';
	}

	/*---- メソッド ----*/
	// 外部インターフェースを意図

	// 下位クラスで書き換えを意図

	/*
	 * コメントの属性を取得する。
	 * @param title	コメントのタイトル
	 * @return コメントの属性から属性値へのハッシュ
	 */
	this.CommentAttr = CRCHalo4iBlog_CommentAttr;

	/*
	 * item 出力用の HTML を生成する
	 * @param itemIdx	何番目のアイテムか
	 * @param channel	channel 要素をハッシュ化したもの
	 * @return HTML を表す文字列
	 * コメントがブログのエントリに対するものでないときは空文字列
	 */
	this.ItemHTML = CRCHalo4iBlog_ItemHTML;

	// このクラスおよび下位クラスでの使用を意図

	// このクラスでのみ使用を意図

}

/*---- メソッドの実装 ----*/
function CRCHalo4iBlog_CommentAttr(title) {
	var	hash = CRCHalo_CommentAttr(title);
	var	i;

	// カテゴリ ID を取得する
	for (i = 0; i < entryUUIDsList.length; i++) {
		if (entryUUIDsList[i] == hash['thread']) {
			hash['categoryUUID'] = getCategoryUUIDForEntry(hash['thread']);
			break;
		}
	}

	return hash;
}

function CRCHalo4iBlog_ItemHTML(itemIdx, channel) {
	var	html;
	var	hash;

	// コメントの属性を取得する
	hash = this.CommentAttr(channel['item'][itemIdx]['title']);
	if (!hash['categoryUUID']) return '';

	// アイテム(コメント)用の HTML を生成する。
	html = '<dt>'
		+ '<a href="'
		+ this.m_BlogBaseURL
		+ hash['categoryUUID']
		+ '/'
		+ this.SafeHTMLAttrText(hash['thread'])
		+ '/index.html">'
		+ this.SafeHTMLText(hash['thread'])
		+ '</a>'
		+ ' : '
		+ '<a href="'
		+ this.CommentURL(this.SafeHTMLAttrText(
		  	channel['item'][itemIdx]['link']
		  ))
		+ '">'
		+ this.SafeHTMLText(hash['post'])
		+ '</a>'
		+ '</dt>'
		+ '<dd>'
		+ this.Text2HTML(channel['item'][itemIdx]['description'])
		+ '</dd>'
	;

	return html;
}
