/*
 * truncatable 1.0 - jQuery Truncate Plugin
 *
 * Copyright (c) 2010 Brandon Kidd (http://www.kiddart.com/)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) 
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 *
 * USAGE:
 * $('.whatever').bkTruncate();
 *
 * OPTIONS:
 * ellipsisText - Default: '...'
 * The text the proceeds the truncated text snippet.
 *
 * maxLength - Default: 100
 * The amount of characters to search and snip.
 *
 * moreText - Default: 'more »'
 * The text that will appear in the link to expand the snippet and show the full text.
 *
 * moreClass - Default: ''
 * The class that will be given to each expand link.
 *
 * moreAlt - Default: 'Click here to read more'
 * The title that will be given to each expand link.
 *
 * showLess - Default: true
 * Whether to show the less link.
 *
 * lessText - Default: '« less'
 * The text that will appear in the link to collapse the snippet and show the trimmed text.
 *
 * lessClass - Default: ''
 * The class that will be given to each collapse link.
 *
 * lessAlt - Default: 'Click here to read less'
 * The title that will be given to each collapse link.
 *
 */
(function(a){a.fn.bkTruncate=function(b){var c={ellipsisText:"...",maxLength:100,moreText:"more &raquo;",moreClass:"",moreAlt:"Click here to read more",showLess:true,lessText:"&laquo; less",lessClass:"",lessAlt:"Click here to read less"};var b=a.extend(c,b);return this.each(function(g){var d=a(this).html().length;if(d>c.maxLength){var k=a(this).html().substr(c.maxLength);var f=k.substr(0,1);var l=new RegExp(/^\s+$/);for(var j=c.maxLength;j<d;j++){var i=a(this).html().substr(0,j);var m=a(this).html().substr(j);var e=i.slice(-1);if(l.test(e)){var o='<span class="hiddenText_'+g+'" style="display: none;">'+m+"</span>";var n=(j-1);var h=a("<a>").attr("class","more_"+g+"");a(this).html(a(this).html().substr(0,n)).append('<span class="ellipsis_'+g+'">'+c.ellipsisText+'</span> <a href="javascript:void(0);" class="'+c.moreClass+" more_"+g+'" title="'+c.moreAlt+'">'+c.moreText+"<a/> "+o);a("a.more_"+g).bind("click",function(){a("span.hiddenText_"+g).show();a("a.more_"+g+", span.ellipsis_"+g).hide();if(c.showLess==true){a("span.hiddenText_"+g).append('<a href="javascript:void(0);" class="'+c.lessClass+" hide_"+g+'" title="'+c.lessAlt+'">'+c.lessText+"</a>");a("a.hide_"+g).bind("click",function(){a(".hiddenText_"+g).hide();a(".more_"+g+", span.ellipsis_"+g).show();a(".hide_"+g).empty();return false})}});j=d}}}})}})(jQuery);
