function init_blabber_busters()
{
	(function($){
		$('.blabber_buster').each(function(i,e){
			var id = $(e).attr('id'),
				size = $(e).attr('class').split("bb_size_")[1].split(" "),
				html = $(e).html(),
				len = html.length,
				pre = '',
				more = '',
				num_chars = 0,
				cur_char = '',
				split_pos = 0,
				in_tag = false,
				more_id = id + '_m',
				control_id = id + '_c',
				ellipsis_id = id + '_e',
				log = '';
				
			if(len <= size)
				return;
			
			//have to find out the 
			while(size > num_chars)
			{	
				cur_char = html.charAt(split_pos);
				//log += cur_char + '; ' + in_tag + '; ';
				if(cur_char == '<')
					in_tag = true;
				
				if(!in_tag)
					num_chars++;
				
				split_pos++;
				
				//log += split_pos + '; ' + num_chars + '\n';
				if(cur_char == '>')
					in_tag = false;
				
			}
			pre = html.substr(0,split_pos);
			more = html.substr(split_pos,len);
			
			$(e).html(pre + '<span id="' + ellipsis_id + '">...</span><span id="' + more_id + '" style="display:none;">' + more + '</span> <a id="' + control_id + '" class="blabber_buster_link" href="javascript:blabber_buster_toggle(\'' + id + '\')">show more</a>');
		});
	})(jQuery)
}

function blabber_buster_toggle(id)
{
	var control = jQuery('#'+id+'_c'),
		more = jQuery('#'+id+'_m'),
		ellipsis = jQuery('#'+id+'_e');

	more.toggle();
	ellipsis.toggle();
	//console.log(control);
	if(more.css('display') == 'none')
		control.html('show more');
	else
		control.html('show less');
	
	//console.log(jQuery(id);
	//jQuery(id).toggle();
}

jQuery(document).ready(init_blabber_busters);
