/*
	File: emoticons.js
	About: This plugin replaces text emoticons with images. Default images are from WordPress.
	Logahead Version: Beta 1.0
    Script Version: 0.1
	Licence: GPL
    Autor: Victor Pimentel http://lapapelera.org
*/

//This variable specify style icons, this script version only support 'wordpress' and 'mini' styles.
var style = 'wordpress';

//This array contains every emoticons, the original text and its replacement. Add a line if you want add more emoticons.
var icons = new Object();

icons[':)'] = icons[':-)'] = icons[':smile:'] = 'smile';
icons[':D'] = icons[':-D'] = icons[':grin:'] = 'biggrin';
icons[':('] = icons[':-('] = icons[':sad:'] = 'sad';
icons[':o'] = icons[':-o'] = icons[':eek:'] = 'surprised';
icons['8O'] = icons['8-O'] = icons[':shock:'] = 'eek';
icons[':?'] = icons[':-?'] = icons[':???:'] = 'confused';
icons['8)'] = icons['8-)'] = icons[':cool:'] = 'cool';
icons[':lol:'] = 'lol';
icons[':x'] = icons[':-x'] = icons[':mad:'] = 'mad';
icons[':P'] = icons[':-P'] = icons[':razz:'] = 'razz';
icons[':oops:'] = 'redface';
icons[':\'('] = icons[':\'-('] = icons['\;('] = icons['\;-('] = icons[':cry:'] = 'cry';
icons[':evil:'] = 'evil';
icons[':twisted:'] = 'twisted';
icons[':roll:'] = 'rolleyes';
icons['\;)'] = icons['\;-)'] = icons[':wink:'] = 'wink';
icons[':!:'] = 'exclaim';
icons[':idea:'] = 'idea';
icons[':arrow:'] = 'arrow';
icons[':|'] = icons[':-|'] = icons[':neutral:'] = 'neutral';
icons[':mrgreen:'] = 'mrgreen';

//This function replaces text emoticons with images.
function addemoticons() {
	
	// The text we have to parse, there are many ways to optimizer this.
	var text = '';
	
	// All the divs
	var divs = document.getElementsByTagName('div');
	
	// Search all keys in the array and replaces text with the image
	for (i=0;i<divs.length;i++)	{
		
		if ( divs[i].className == 'cont' ) {
			text = divs[i].innerHTML;
			for ( key in icons )
				text = unescape(escape(text).replace ( new RegExp(escape(key),'ig') , "<img class=\"icons\" src=\"extras/plugins/emoticons/" + style + "/icon_" + icons[key] + ".gif\" alt=\"" + key +"\" />"));
			divs[i].innerHTML = text;
		}
		
	}
	
}

//With this function 'addemoticons' will be called when the pages loads.
addLoadEvent(addemoticons);