(function() {
	var emoticon= {
		":-@": "/awe2public/gfx/smileys/angry.gif",
		"B-)": "/awe2public/gfx/smileys/cool.gif",
		":-S": "/awe2public/gfx/smileys/embarrassed.gif",
		":-D": "/awe2public/gfx/smileys/laugh.gif",
		"|:|": "/awe2public/gfx/smileys/ninja.gif",
		"*-)": "/awe2public/gfx/smileys/perplex.gif",
		"P-)": "/awe2public/gfx/smileys/pirate.gif",
		":-(": "/awe2public/gfx/smileys/sad.gif",
		":-)": "/awe2public/gfx/smileys/smile.gif",
		";-)": "/awe2public/gfx/smileys/wink.gif",
		"<:)": "/awe2public/gfx/smileys/xmas.gif"
	};

	// surely this must be standart somewhere?
	var quotemeta= function(str) {
		str= str.replace(/\\/g, '\\');
		str= str.replace(/([()\-\|\[\]?*])/g, '\\$1');
		return str;
	}

	var res= new Array();
	for(var x in emoticon) {
		res.push(quotemeta(x));
	}
	var re= new RegExp("(" + res.join("|") + ")", 'g');

	jQuery.fn.emoticon= function() {
		this.each(function(){
			if(this.nodeType == 3) {
				var text = this.nodeValue;
				text= text.replace(re, function(x) {
					return "<img alt=\""+x+"\" src=\""+emoticon[x]+"\">"; 
				});
				$(this).replaceWith(text);
			} else {
				$(this).contents().emoticon();
			}
		});
	};
})();


