imgList = new Array();

function setImgList() {
	imgList[imgList.length] = new Array("ｵﾊﾖ","http://www.harbotsfield.com/blog/livly/ohayo.gif");
	imgList[imgList.length] = new Array("ｺﾝﾆﾁﾊ","http://www.harbotsfield.com/blog/livly/konnitiha.gif");
	imgList[imgList.length] = new Array("ｺﾊﾞﾜ","http://www.harbotsfield.com/blog/livly/kobawa.gif");

	imgList[imgList.length] = new Array("ｵﾒﾃﾞﾄ","http://www.harbotsfield.com/blog/livly/omedeto.gif");
	imgList[imgList.length] = new Array("ﾖｶｯﾀ","http://www.harbotsfield.com/blog/livly/yokatta.gif");
	imgList[imgList.length] = new Array("ﾆｺｯ","http://www.harbotsfield.com/blog/livly/niko.gif");
	imgList[imgList.length] = new Array("ｳﾝ","http://www.harbotsfield.com/blog/livly/un.gif");

	imgList[imgList.length] = new Array("ｱﾘｶﾞﾄｳ","http://www.harbotsfield.com/blog/livly/arigato.gif");
	imgList[imgList.length] = new Array("ｳﾚｼｲ","http://www.harbotsfield.com/blog/livly/uresii.gif");
	imgList[imgList.length] = new Array("ﾜｰｲ","http://www.harbotsfield.com/blog/livly/wai.gif");
	imgList[imgList.length] = new Array("ｱﾊﾊ","http://www.harbotsfield.com/blog/livly/ahaha.gif");

	imgList[imgList.length] = new Array("ｵｰ","http://www.harbotsfield.com/blog/livly/o.gif");
	imgList[imgList.length] = new Array("ﾖﾛｼｸ","http://www.harbotsfield.com/blog/livly/yorosiku.gif");
	imgList[imgList.length] = new Array("ｵﾈｶﾞｲ","http://www.harbotsfield.com/blog/livly/onegai.gif");
	imgList[imgList.length] = new Array("ﾈ!","http://www.harbotsfield.com/blog/livly/ne.gif");

	imgList[imgList.length] = new Array("ﾋﾞｯｸﾘ","http://www.harbotsfield.com/blog/livly/bikuri.gif");
	imgList[imgList.length] = new Array("ｲｴｲｴ","http://www.harbotsfield.com/blog/livly/ieie.gif");
	imgList[imgList.length] = new Array("ｶﾞﾝﾊﾞﾛ","http://www.harbotsfield.com/blog/livly/ganbaro.gif");
	imgList[imgList.length] = new Array("ｶﾞﾝﾊﾞﾚ","http://www.harbotsfield.com/blog/livly/ganbare.gif");

	imgList[imgList.length] = new Array("ｻﾞﾝﾈﾝ","http://www.harbotsfield.com/blog/livly/zannen.gif");
	imgList[imgList.length] = new Array("ﾌｳ","http://www.harbotsfield.com/blog/livly/fuu.gif");
	imgList[imgList.length] = new Array("ｳｰﾝ","http://www.harbotsfield.com/blog/livly/u-n.gif");
	imgList[imgList.length] = new Array("･･･","http://www.harbotsfield.com/blog/livly/ten.gif");

	imgList[imgList.length] = new Array("ｺﾞﾒﾝ","http://www.harbotsfield.com/blog/livly/gomen.gif");
	imgList[imgList.length] = new Array("ｳｯ","http://www.harbotsfield.com/blog/livly/u.gif");
	imgList[imgList.length] = new Array("ｸﾞｽｯ","http://www.harbotsfield.com/blog/livly/gusu.gif");
	imgList[imgList.length] = new Array("ｸｽﾝ","http://www.harbotsfield.com/blog/livly/kusun.gif");

	imgList[imgList.length] = new Array("ﾄﾞｳ","http://www.harbotsfield.com/blog/livly/dou.gif");
	imgList[imgList.length] = new Array("ﾝ","http://www.harbotsfield.com/blog/livly/n.gif");
	imgList[imgList.length] = new Array("ｱﾚ","http://www.harbotsfield.com/blog/livly/are.gif");
	imgList[imgList.length] = new Array("ﾒｯ!","http://www.harbotsfield.com/blog/livly/me.gif");

	imgList[imgList.length] = new Array("ﾊｰﾄ","http://www.harbotsfield.com/blog/livly/haato.gif");
	imgList[imgList.length] = new Array("ﾎｼ","http://www.harbotsfield.com/blog/livly/hosi.GIF");
	imgList[imgList.length] = new Array("ﾊﾃﾅ","http://www.harbotsfield.com/blog/livly/hatena.gif");
	imgList[imgList.length] = new Array("♪","http://www.harbotsfield.com/blog/livly/onpu.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 = 34;
	//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==35) 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://kuikku.blog.so-net.ne.jp/2008-10-09-1\" target=\"_blank\"><img border=\"0\" src=\"http://www.harbotsfield.com/blog/livly/pigumiemoji.gif\" alt=\"(C)2008 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://kuikku.blog.so-net.ne.jp/2008-10-09-1\" target=\"_blank\"><img border=\"0\" src=\"http://www.harbotsfield.com/blog/livly/pigumiemoji.gif\" alt=\"(C)2008 kuu All Rights Reserved\" /></a></dt><dd>"+imgText+"<br><small>(C) 2008 <a href=\"http://kuikku.blog.so-net.ne.jp/\" 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.livly.com/main.php\" target=\"_blank\">Livly Island</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://kuikku.blog.so-net.ne.jp/2008-10-09-1\" target=\"_blank\"><img border=\"0\" src=\"http://www.harbotsfield.com/blog/livly/pigumiemoji.gif\" alt=\"(C)2008 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;

