imgList = new Array();

function setImgList() {
	imgList[imgList.length] = new Array("ｵﾊﾖ","http://www.harbotsfield.com/blog/habo/ohayo-02.gif");
	imgList[imgList.length] = new Array("ｺﾝﾆﾁﾊ","http://www.harbotsfield.com/blog/habo/konnitiha-02.gif");
	imgList[imgList.length] = new Array("ｺﾊﾞﾜ","http://www.harbotsfield.com/blog/habo/kobawa-02.gif");
	imgList[imgList.length] = new Array("ｳｽ","http://www.harbotsfield.com/blog/habo/usu-01.gif");
	imgList[imgList.length] = new Array("ｵﾒﾃﾞﾄ","http://www.harbotsfield.com/blog/habo/omedeto-03.gif");
	imgList[imgList.length] = new Array("ｱﾘｶﾞﾄｳ","http://www.harbotsfield.com/blog/habo/arigato-02.gif");
	imgList[imgList.length] = new Array("ﾖｶｯﾀ","http://www.harbotsfield.com/blog/habo/yokatta.gif");
	imgList[imgList.length] = new Array("ｳﾚｼｲ","http://www.harbotsfield.com/blog/habo/uresii-02.gif");
	imgList[imgList.length] = new Array("ﾆｺｯ","http://www.harbotsfield.com/blog/habo/niko.gif");
	imgList[imgList.length] = new Array("ﾔﾀ","http://www.harbotsfield.com/blog/habo/yata-01.gif");
	imgList[imgList.length] = new Array("ｵｰ","http://www.harbotsfield.com/blog/habo/o.gif");
	imgList[imgList.length] = new Array("ﾜｰｲ","http://www.harbotsfield.com/blog/habo/wai-01.gif");
	imgList[imgList.length] = new Array("ｱﾊﾊ","http://www.harbotsfield.com/blog/habo/ahaha.gif");
	imgList[imgList.length] = new Array("ﾖﾛｼｸ","http://www.harbotsfield.com/blog/habo/yorosiku.gif");
	imgList[imgList.length] = new Array("ｵﾈｶﾞｲ","http://www.harbotsfield.com/blog/habo/onegai-02.gif");
	imgList[imgList.length] = new Array("ﾋﾞｯｸﾘ","http://www.harbotsfield.com/blog/habo/bikuri.gif");
	imgList[imgList.length] = new Array("ｲｴｲｴ","http://www.harbotsfield.com/blog/habo/ieie.gif");
	imgList[imgList.length] = new Array("ｳﾝ","http://www.harbotsfield.com/blog/habo/un.gif");
	imgList[imgList.length] = new Array("ﾈ!","http://www.harbotsfield.com/blog/habo/ne.gif");
	imgList[imgList.length] = new Array("ｶﾞﾝﾊﾞﾛ","http://www.harbotsfield.com/blog/habo/ganbaro-01.gif");
	imgList[imgList.length] = new Array("ｶﾞﾝﾊﾞﾚ","http://www.harbotsfield.com/blog/habo/ganbare.gif");
	imgList[imgList.length] = new Array("ｻﾞﾝﾈﾝ","http://www.harbotsfield.com/blog/habo/zannen.gif");
	imgList[imgList.length] = new Array("ｺﾞﾒﾝ","http://www.harbotsfield.com/blog/habo/gomen-01.gif");
	imgList[imgList.length] = new Array("ﾌｳ","http://www.harbotsfield.com/blog/habo/fuu.gif");
	imgList[imgList.length] = new Array("ｳｯ","http://www.harbotsfield.com/blog/habo/u-01.gif");
	imgList[imgList.length] = new Array("ｳｰﾝ","http://www.harbotsfield.com/blog/habo/un-01.gif");
	imgList[imgList.length] = new Array("ｸﾞｽｯ","http://www.harbotsfield.com/blog/habo/gusu.gif");
	imgList[imgList.length] = new Array("ｸｽﾝ","http://www.harbotsfield.com/blog/habo/kusun.gif");
	imgList[imgList.length] = new Array("･･･","http://www.harbotsfield.com/blog/habo/ten.gif");
	imgList[imgList.length] = new Array("ﾄﾞｳ","http://www.harbotsfield.com/blog/habo/dou.gif");
	imgList[imgList.length] = new Array("ｱﾚ","http://www.harbotsfield.com/blog/habo/are.gif");
	imgList[imgList.length] = new Array("ﾒｯ!","http://www.harbotsfield.com/blog/habo/me.gif");
	imgList[imgList.length] = new Array("ﾊｰﾄ","http://www.harbotsfield.com/blog/habo/haato.gif");
	imgList[imgList.length] = new Array("ﾎｼ","http://www.harbotsfield.com/blog/habo/hosi.GIF");
	imgList[imgList.length] = new Array("ﾊﾃﾅ","http://www.harbotsfield.com/blog/habo/hatena.gif");
	imgList[imgList.length] = new Array("♪","http://www.harbotsfield.com/blog/habo/onpu.gif");
	imgList[imgList.length] = new Array("ﾊｰﾎﾞｯﾄ","http://www.harbotsfield.com/blog/habo/harbot-01.gif");
	imgList[imgList.length] = new Array("ﾌｰﾎﾞﾝ","http://www.harbotsfield.com/blog/habo/fubon.gif");
	imgList[imgList.length] = new Array("ﾊﾞﾝﾎﾞﾝ","http://www.harbotsfield.com/blog/habo/banbon.gif");
	imgList[imgList.length] = new Array("ｻﾝﾎﾞﾝ","http://www.harbotsfield.com/blog/habo/sanbon.gif");
	imgList[imgList.length] = new Array("ﾄｰﾎﾞﾝ","http://www.harbotsfield.com/blog/habo/tobon.gif");
}

setImgList();

img = new Array();

for (i=0; i < imgList.length; i++) {
	img[i] = new Image();
	img[i].src = imgList[i][1];
}

/* コメントエリアに絵文字アイコンを挿入 */
function cmtEdit() {
	var limit = 40;
	//var imgText = "<dd>";
	var imgText = "";
	for (i=0; i < imgList.length; i++) {
		imgText += "<a href='javascript:;' onClick='addImageTag("+i+");'><img style='margin:2px 2px' border='0' src='"+imgList[i][1]+"' name='img"+i+"' alt=\""+imgList[i][0]+"\" /></a>";
		//imgText += "<a href='javascript:;' onClick='addImageTag("+i+");'><img border='0' name='img"+i+"' alt=\""+imgList[i][0]+"\" /></a>";
		if (i==41) imgText += "<br>";
		if (i==limit) break;
	}
	//imgText += "</dd>";
	obj = document.getElementById("comment-write").innerHTML;
	//document.getElementById("comment-write").innerHTML = obj.replace(/(<.*コメント：)/i,"<td><a class=\"site_title\" href=\"http://blog.so-net.ne.jp/dayan/2007-11-11-1\" target=\"_blank\"><img border=\"0\" src=\"http://www.harbotsfield.com/blog/habo/habomoji2.gif\" alt=\"(C)2007 kuu All Rights Reserved\" /></a></td><td>"+imgText+"</td>\r\n\t\t</tr><tr>\r\n\t\t\t\t$1");
	if (obj.match(/(<dt.*コメント：)/i)) {
		document.getElementById("comment-write").innerHTML = obj.replace(/(<dt.*コメント：)/i,"<dt><a class=\"site_title\" href=\"http://blog.so-net.ne.jp/dayan/2007-11-11-1\" target=\"_blank\"><img border=\"0\" src=\"http://www.harbotsfield.com/blog/habo/habomoji2.gif\" alt=\"(C)2007 kuu All Rights Reserved\" /></a></dt><dd>"+imgText+"<br><small>(C) 2007 <a href=\"http://blog.so-net.ne.jp/dayan/\" target=\"_blank\">kuu</a> All Rights Reserved // original script is <a href=\"http://blog.so-net.ne.jp/youmode/2006-06-03\" target=\"_blank\">youmode</a> / <a href=\"http://www.so-net.ne.jp/harbot/\" target=\"_blank\">harbot</a></small></dd>\r\n\t\t\t\t$1");
	} else {
		document.getElementById("comment-write").innerHTML = obj.replace(/(<td.*コメント：)/i,"<td><a class=\"site_title\" href=\"http://blog.so-net.ne.jp/dayan/2007-11-11-1\" target=\"_blank\"><img border=\"0\" src=\"http://www.harbotsfield.com/blog/habo/habomoji2.gif\" alt=\"(C)2007 kuu All Rights Reserved\" /></a></td><td>"+imgText+"</td>\r\n\t\t\t\t\t\</tr>\r\n\t\t\t\t\t\t\t$1");
	}

	for (i=0; i < limit+1; i++) {
		setImage("img"+i, img[i].src);
	}
}

/* コメントを絵文字に変換 */
function cmtChange() {
	c_obj = document.getElementById("comments").innerHTML;
	for (i=0; i < imgList.length; i++) {
		rep = '\\['+imgList[i][0]+'\\]';
		re = new RegExp(rep, "g");
		document.getElementById("comments").innerHTML = c_obj.replace(re, "<img style='vertical-align:middle;float:none;margin:0 0' src='"+imgList[i][1]+"' />");
		c_obj = document.getElementById("comments").innerHTML;
	}
}

/* 絵文字をセット */
function setImage(name, src) {
	if (document.images) {
		//document.images[name].src = src;
	}
}

/* テキストエリアにタグを挿入 */
function addImageTag(no) {
	var f = document.forms[1].article_child__body;
	var tag = "["+imgList[no][0]+"]";
	if (document.selection) {
		f.focus();
		var sel = document.selection.createRange();
		sel.text = tag;
	} else if (f.selectionStart || f.selectionStart == '0') {
		var startPos = f.selectionStart;
		var endPos = f.selectionEnd;
		f.value = f.value.substring(0, startPos) + tag + f.value.substring(endPos);
	} else {
		f.value += tag;
	}
}

/* onload */
function onloadH(e) {
	var blogElements = document.getElementsByTagName("div");
	for (i = 0; i < blogElements.length; i++) {
		if (blogElements[i].id == "comment-write") {
			cmtEdit();
			//コメント量が多ければ変換しない
			var cid = "comments";
			c_obj = document.getElementById(cid).innerHTML;
			//alert(c_obj.length);
			if (c_obj.length > 7620) {
				rep = '(<H4.*/H4>)';
				re = new RegExp(rep, "i");
				document.getElementById(cid).innerHTML = c_obj.replace(re, "$1<input type=\"button\" value=\"絵文字変換\" onClick=\"cmtChange('comments')\">（※PCスペックが低いと時間がかかる場合があります。）");
			} else {
				cmtChange("comments");
			}
			break;
		}
	}
	return true;
}

window.onload = onloadH;
