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://hellodeedee.com/wp-includes/images/smilies/1shocked.gif" alt=":1shocked:" onclick="grin(\':1shocked:\');"/> <img src="http://hellodeedee.com/wp-includes/images/smilies/1sad.gif" alt=":1sad:" onclick="grin(\':1sad:\');"/> <img src="http://hellodeedee.com/wp-includes/images/smilies/1perplexed.gif" alt=":1perplexed:" onclick="grin(\':1perplexed:\');"/> <img src="http://hellodeedee.com/wp-includes/images/smilies/1meh.gif" alt=":1meh:" onclick="grin(\':1meh:\');"/> <img src="http://hellodeedee.com/wp-includes/images/smilies/1littleschocked.gif" alt=":1littleshocked:" onclick="grin(\':1littleshocked:\');"/> <img src="http://hellodeedee.com/wp-includes/images/smilies/1inlove.gif" alt=":1hi5:" onclick="grin(\':1hi5:\');"/> <img src="http://hellodeedee.com/wp-includes/images/smilies/1happy.gif" alt=":1happy:" onclick="grin(\':1happy:\');"/> <img src="http://hellodeedee.com/wp-includes/images/smilies/1embarrassed.gif" alt=":1embarrassed:" onclick="grin(\':1embarrassed:\');"/> <img src="http://hellodeedee.com/wp-includes/images/smilies/1dirtystare.gif" alt=":1dirtystare:" onclick="grin(\':1dirtystare:\');"/> <img src="http://hellodeedee.com/wp-includes/images/smilies/1dead.gif" alt=":1dead:" onclick="grin(\':1dead:\');"/> <img src="http://hellodeedee.com/wp-includes/images/smilies/1cry.gif" alt=":1cry:" onclick="grin(\':1cry:\');"/> <img src="http://hellodeedee.com/wp-includes/images/smilies/1content.gif" alt=":1content:" onclick="grin(\':1content:\');"/> <img src="http://hellodeedee.com/wp-includes/images/smilies/1confused.gif" alt=":1confused:" onclick="grin(\':1confused:\');"/> <img src="http://hellodeedee.com/wp-includes/images/smilies/1cheerful.gif" alt=":1cheerful:" onclick="grin(\':1cheerful:\');"/> <img src="http://hellodeedee.com/wp-includes/images/smilies/1bleh.gif" alt=":1bleh:" onclick="grin(\':1bleh:\');"/> <img src="http://hellodeedee.com/wp-includes/images/smilies/1blank.gif" alt=":1blank:" onclick="grin(\':1blank:\');"/> <img src="http://hellodeedee.com/wp-includes/images/smilies/1blank2.gif" alt=":1blank2:" onclick="grin(\':1blank2:\');"/> <img src="http://hellodeedee.com/wp-includes/images/smilies/1aww.gif" alt=":1aww:" onclick="grin(\':1aww:\');"/> <img src="http://hellodeedee.com/wp-includes/images/smilies/1argh.gif" alt=":1argh:" onclick="grin(\':1argh:\');"/> <img src="http://hellodeedee.com/wp-includes/images/smilies/1argh2.gif" alt=":1argh2:" onclick="grin(\':1argh2:\');"/> <img src="http://hellodeedee.com/wp-includes/images/smilies/1yay.gif" alt="1yay" onclick="grin(\'1yay\');"/> <img src="http://hellodeedee.com/wp-includes/images/smilies/1yawn.gif" alt="1yawn" onclick="grin(\'1yawn\');"/> <img src="http://hellodeedee.com/wp-includes/images/smilies/1wtf.gif" alt="1wtf" onclick="grin(\'1wtf\');"/> <img src="http://hellodeedee.com/wp-includes/images/smilies/1wink.gif" alt="1wink" onclick="grin(\'1wink\');"/> <img src="http://hellodeedee.com/wp-includes/images/smilies/1vhappy.gif" alt="1vhappy" onclick="grin(\'1vhappy\');"/> <img src="http://hellodeedee.com/wp-includes/images/smilies/1sweat2.gif" alt="1sweat2" onclick="grin(\'1sweat2\');"/> <img src="http://hellodeedee.com/wp-includes/images/smilies/1smile2.gif" alt="1smile2" onclick="grin(\'1smile2\');"/> <img src="http://hellodeedee.com/wp-includes/images/smilies/1smile.gif" alt="1smile" onclick="grin(\'1smile\');"/> <img src="http://hellodeedee.com/wp-includes/images/smilies/1sigh.gif" alt="1sigh" onclick="grin(\'1sigh\');"/> ';
	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();
	}
}
