/**
 * Smileyhandler v1.0
 * http://www.sxdev.be/
 * 
 * Written by Hans De Mulder
 * Copyright (c) 2009 Hans De Mulder
 * 
 * Licensed under the GPL v3 license.
 * 
 * Date: 2009-08-12 02:15:00 +0100 (Wed, 12 Aug 2009)
 * Revision: 7
 */
/**
 * Dependancies:
 * ============
 * 
 * jQuery (tested on jQuery v1.3.2)
 * str_replace (http://phpjs.org/)
 * 
 * This handler needs an array (smilies) with following format:
 * 
 * smilies[num_key] = new Array();
 *     smilies[num_key][0] = 'url to smiley (image)';
 *     smilies[num_key][1] = new Array('aliases for the smiley (strings that will be replaced by the image) in this array');
 *
 * Note: num_key needs to be incremental (integer!)
 */
/**
 * Each smiley will be replaced by:
 *     <img src="URL TO SMILEY" alt="ALIAS" class="smiley" />
 */

function SmileyHandler(smileys)
{
	smlength = smileys.length;
	 
	if(smlength == 0)
	{
		return;
	}
	
	$(".cb_text p").each(function() {
		for(i = 0; i < smlength; i++)
		{
			for(j = 0; j < smileys[i][1].length; j++)
			{
				SmileyImgTag = '<img src="'+ smileys[i][0] +'" alt="'+ smileys[i][1][j] +'" class="smiley" />';
				this.innerHTML = str_replace(smileys[i][1][j], SmileyImgTag, this.innerHTML);
			}
			delete(j);
		}
		delete(i);
	});
	
	delete(smlength);
}
