function insertAfter(node, referenceNode) {
	referenceNode.parentNode.insertBefore(node, referenceNode.nextSibling);
}
function loadGrins() {
	var grinsDiv = document.createElement('div');
	grinsDiv.id = 'wp_grins';
	grinsDiv.innerHTML = '<img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/icon_wink.gif" alt=";-)" onclick="grin(\';-)\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/icon_neutral.gif" alt=":|" onclick="grin(\':|\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/yahho01.gif" alt=":yahho01:" onclick="grin(\':yahho01:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/icon_mad.gif" alt=":x" onclick="grin(\':x\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/w03.gif" alt=":w03:" onclick="grin(\':w03:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/w02.gif" alt=":w02:" onclick="grin(\':w02:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/umbrella.gif" alt=":umbrella:" onclick="grin(\':umbrella:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/icon_twisted.gif" alt=":twisted:" onclick="grin(\':twisted:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/sweat.gif" alt=":sweat:" onclick="grin(\':sweat:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/sun.gif" alt=":sun:" onclick="grin(\':sun:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/star.gif" alt=":star:" onclick="grin(\':star:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/sparkling.gif" alt=":sparkling:" onclick="grin(\':sparkling:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/snowman.gif" alt=":snowman:" onclick="grin(\':snowman:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/icon_smile.gif" alt=":smile:" onclick="grin(\':smile:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/icon_eek.gif" alt=":shock:" onclick="grin(\':shock:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/icon_sad.gif" alt=":sad:" onclick="grin(\':sad:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/icon_rolleyes.gif" alt=":roll:" onclick="grin(\':roll:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/icon_razz.gif" alt=":razz:" onclick="grin(\':razz:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/rainy.gif" alt=":rainy:" onclick="grin(\':rainy:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/postmark.gif" alt=":postmark:" onclick="grin(\':postmark:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/icon_redface.gif" alt=":oops:" onclick="grin(\':oops:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/onegai03t.gif" alt=":onegai03t:" onclick="grin(\':onegai03t:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/onegai02t.gif" alt=":onegai02t:" onclick="grin(\':onegai02t:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/onegai01t.gif" alt=":onegai01t:" onclick="grin(\':onegai01t:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/ok.gif" alt=":ok:" onclick="grin(\':ok:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/icon_surprised.gif" alt=":o" onclick="grin(\':o\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/note.gif" alt=":note:" onclick="grin(\':note:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/naku02.gif" alt=":naku02:" onclick="grin(\':naku02:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/mystify.gif" alt=":mystify:" onclick="grin(\':mystify:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/icon_mrgreen.gif" alt=":mrgreen:" onclick="grin(\':mrgreen:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/moon.gif" alt=":moon:" onclick="grin(\':moon:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/mark_question.gif" alt=":mark_question:" onclick="grin(\':mark_question:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/mark_ecstoramation.gif" alt=":mark_ecstoramation:" onclick="grin(\':mark_ecstoramation:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/icon_lol.gif" alt=":lol:" onclick="grin(\':lol:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/ikari02.gif" alt=":ikari02:" onclick="grin(\':ikari02:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/icon_idea.gif" alt=":idea:" onclick="grin(\':idea:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/hearts.gif" alt=":hearts:" onclick="grin(\':hearts:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/heart_shake.gif" alt=":heart_shake:" onclick="grin(\':heart_shake:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/heart.gif" alt=":heart:" onclick="grin(\':heart:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/heart18.gif" alt=":heart18:" onclick="grin(\':heart18:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/icon_biggrin.gif" alt=":grin:" onclick="grin(\':grin:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/ga-n01.gif" alt=":ga-n01:" onclick="grin(\':ga-n01:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/face_watching.gif" alt=":face_watching:" onclick="grin(\':face_watching:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/face_surprised.gif" alt=":face_surprised:" onclick="grin(\':face_surprised:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/face_sparkling_smile.gif" alt=":face_sparkling_smile:" onclick="grin(\':face_sparkling_smile:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/face_smile.gif" alt=":face_smile:" onclick="grin(\':face_smile:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/face_shy.gif" alt=":face_shy:" onclick="grin(\':face_shy:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/face_shout.gif" alt=":face_shout:" onclick="grin(\':face_shout:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/face_shock.gif" alt=":face_shock:" onclick="grin(\':face_shock:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/face_shishishi.gif" alt=":face_shishishi:" onclick="grin(\':face_shishishi:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/face_self-conscious_smile.gif" alt=":face_self-conscious_smile:" onclick="grin(\':face_self-conscious_smile:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/face_sad.gif" alt=":face_sad:" onclick="grin(\':face_sad:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/face_mistake.gif" alt=":face_mistake:" onclick="grin(\':face_mistake:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/face_mischievous.gif" alt=":face_mischievous:" onclick="grin(\':face_mischievous:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/face_love.gif" alt=":face_love:" onclick="grin(\':face_love:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/face_expressionless.gif" alt=":face_expressionless:" onclick="grin(\':face_expressionless:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/face_embarrassed.gif" alt=":face_embarrassed:" onclick="grin(\':face_embarrassed:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/face_chomp.gif" alt=":face_chomp:" onclick="grin(\':face_chomp:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/icon_evil.gif" alt=":evil:" onclick="grin(\':evil:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/cursor_up.gif" alt=":cursor_up:" onclick="grin(\':cursor_up:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/cursor_down.gif" alt=":cursor_down:" onclick="grin(\':cursor_down:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/icon_cry.gif" alt=":cry:" onclick="grin(\':cry:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/crown04.gif" alt=":crown04:" onclick="grin(\':crown04:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/icon_cool.gif" alt=":cool:" onclick="grin(\':cool:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/cloudy.gif" alt=":cloudy:" onclick="grin(\':cloudy:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/check.gif" alt=":check:" onclick="grin(\':check:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/bye03.gif" alt=":bye03:" onclick="grin(\':bye03:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/body_run_away_right.gif" alt=":body_run_away_right:" onclick="grin(\':body_run_away_right:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/body_run_away_left.gif" alt=":body_run_away_left:" onclick="grin(\':body_run_away_left:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/icon_arrow.gif" alt=":arrow:" onclick="grin(\':arrow:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/icon_confused.gif" alt=":???:" onclick="grin(\':???:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/icon_question.gif" alt=":?:" onclick="grin(\':?:\');"/> <img src="http://www.b-blo.com/kotekote/wp-includes/images/smilies/icon_exclaim.gif" alt=":!:" onclick="grin(\':!:\');"/> ';
	if ($('postdiv')) {
		var type = 'child';
		var node = $('postdiv');
	}
	else if (document.getElementById('postdivrich')) {
		var type = 'child';
		var node = $('postdivrich');
	}
	else if (document.getElementById('comment')) {
		var type = 'before';
		var node = $('comment');
	}
	else {
		return;
	}
	switch (type) {
		case 'child':
			grinsDiv.style.paddingTop = '5px';
			node.appendChild(grinsDiv);
			break;
		case 'before':
			node.parentNode.insertBefore(grinsDiv, node);
			break;
	}
}
Event.observe(window, 'load', loadGrins, false);
function grin(tag) {
	var myField;
	if ($('content') && $('content').type == 'textarea') {
		myField = document.getElementById('content');
		if ($('postdivrich') && typeof tinyMCE != 'undefined' && (!$('edButtons') || $('quicktags').style.display == 'none')) {
			tinyMCE.execInstanceCommand('mce_editor_0', 'mceInsertContent', false, '&nbsp;' + tag + '&nbsp;');
			tinyMCE.selectedInstance.repaint();
			return;
		}
	}
	else if ($('comment') && $('comment').type == 'textarea') {
		myField = $('comment');
	}
	else {
		return false;
	}
	if (document.selection) {
		myField.focus();
		sel = document.selection.createRange();
		sel.text = ' ' + tag + ' ';
		myField.focus();
	}
	else if (myField.selectionStart || myField.selectionStart == '0') {
		var startPos = myField.selectionStart;
		var endPos = myField.selectionEnd;
		var cursorPos = endPos;
		myField.value = myField.value.substring(0, startPos)
					  + ' ' + tag + ' '
					  + myField.value.substring(endPos, myField.value.length);
		cursorPos += tag.length + 2;
		myField.focus();
		myField.selectionStart = cursorPos;
		myField.selectionEnd = cursorPos;
	}
	else {
		myField.value += tag;
		myField.focus();
	}
}
