(function(D){D.fn.condense=function(H){D.metadata?A("metadata plugin detected"):A("metadata plugin not present");var I=D.extend({},D.fn.condense.defaults,H);return this.each(function(){$this=D(this);var L=D.metadata?D.extend({},I,$this.metadata()):I;A("Condensing ["+$this.text().length+"]: "+$this.text());var M=G($this,L);if(M){$this.attr("id")?$this.attr("id","condensed_"+$this.attr("id")):false;var K=" <span class='condense_control condense_control_more' style='cursor:pointer;'>"+L.moreText+"</span>";var J=" <span class='condense_control condense_control_less' style='cursor:pointer;'>"+L.lessText+"</span>";M.append(L.ellipsis+K);$this.after(M).hide().append(J);D(".condense_control_more",M).click(function(){A("moreControl clicked.");E(D(this),L)});D(".condense_control_less",$this).click(function(){A("lessControl clicked.");C(D(this),L)})}if(typeof L.onInit=="function"){L.onInit.apply(this,[M])}})};function G(K,H){if(D.trim(K.text()).length<=H.condensedLength+H.minTrail){A("element too short: skipping.");return false}var M=D.trim(K.html());var P=D.trim(K.text());var J=H.delim;var O=K.clone();var Q=0;do{var N=B(M,H.delim,(H.condensedLength+Q));O.html(M.substring(0,(N+1)));var I=O.text().length;var L=O.html().length;Q=O.html().length-I;A("condensing... [html-length:"+L+" text-length:"+I+" delta: "+Q+" break-point: "+N+"]")}while(Q&&O.text().length<H.condensedLength);if((P.length-I)<H.minTrail){A("not enough trailing text: skipping.");return false}A("clone condensed. [text-length:"+I+"]");return O}function B(H,L,J){var I=false;var K=J;do{var K=H.indexOf(L,K);if(K<0){A("No delimiter found.");return H.length}I=true;while(F(H,K)){K++;I=false}}while(!I);A("Delimiter found in html at: "+K);return K}function F(H,I){return(H.indexOf(">",I)<H.indexOf("<",I))}function C(L,K){A("Condense Trigger: "+L.html());var O=L.parent();var M=O.next();M.show();var H=M.width();var I=M.height();M.hide();var J=O.width();var N=O.height();O.animate({height:I,width:H,opacity:1},K.lessSpeed,K.easing,function(){O.height(N).width(J).hide();M.show();if(typeof K.onCondense=="function"){K.onCondense.apply(L,[M])}if(typeof K.onToggle=="function"){K.onToggle.apply(L,[O,M,true])}})}function E(J,I){A("Expand Trigger: "+J.html());var K=J.parent();var N=K.prev();N.show();var H=N.width();var M=N.height();N.width(K.width()+"px").height(K.height()+"px");K.hide();N.animate({height:M,width:H,opacity:1},I.moreSpeed,I.easing,function(){if(typeof I.onExpand=="function"){I.onExpand.apply(J,[N])}if(typeof I.onToggle=="function"){I.onToggle.apply(J,[N,K,false])}});if(K.attr("id")){var L=K.attr("id");K.attr("id","condensed_"+L);N.attr("id",L)}}function A(H){if(window.console&&window.console.log){window.console.log(H)}}D.fn.condense.defaults={condensedLength:200,minTrail:20,delim:" ",moreText:"[more]",lessText:"[less]",ellipsis:" ( ... )",moreSpeed:"normal",lessSpeed:"normal",easing:"linear",onInit:null,onCondense:null,onExpand:null,onToggle:null}})(jQuery);