(function($){$.fn.columnize=function(E){var F={width:400,columns:false,buildOnce:false,overflow:false};var E=$.extend(F,E);return this.each(function(){var y=$(this);var z=y.height();var A=$('<div></div>');var B=0;var C=false;var D=y[0].childNodes;y.append($(D));A.append(y.children().clone());columnizeIt();if(!E.buildOnce){$(window).resize(function(){if(!E.buildOnce&&$.browser.msie){if(y.data("timeout")){clearTimeout(y.data("timeout"))}y.data("timeout",setTimeout(columnizeIt,200))}else if(!E.buildOnce){columnizeIt()}else{}})}function columnize(a,b,c,d){while(c.height()<d&&b[0].childNodes.length){a.append(b[0].childNodes[0])}if(a[0].childNodes.length==0)return;var e=a[0].childNodes;var f=e[e.length-1];a[0].removeChild(f);var g=$(f);if(g[0].nodeType==3){var h=g[0].nodeValue;var i=E.width/18;if(E.accuracy)i=E.accuracy;var j;var k=null;while(c.height()<d&&h.length){if(h.indexOf(' ',i)!='-1'){j=h.substring(0,h.indexOf(' ',i))}else{j=h}k=document.createTextNode(j);a.append(k);if(h.length>i){h=h.substring(h.indexOf(' ',i))}else{h=""}}if(c.height()>=d&&k!=null){a[0].removeChild(k);h=k.nodeValue+h}if(h.length){g[0].nodeValue=h}else{return false}}if(b.children().length){b.prepend(g)}else{b.append(g)}return g[0].nodeType==3}function split(a,b,c,d){if(b.children().length){$cloneMe=b.children(":first");$clone=$cloneMe.clone();if($clone.attr("nodeType")==1&&!$clone.hasClass("dontend")){a.append($clone);if($clone.is("img")&&c.height()<d+20){$cloneMe.remove()}else if(!$cloneMe.hasClass("dontsplit")&&c.height()<d+20){$cloneMe.remove()}else if($clone.is("img")||$cloneMe.hasClass("dontsplit")){$clone.remove()}else{$clone.empty();if(!columnize($clone,$cloneMe,c,d)){if($cloneMe.children().length){split($clone,$cloneMe,c,d)}}}}}}function singleColumnizeIt(){if(y.data("columnized")&&y.children().length==1){return}y.data("columnized",true);y.data("columnizing",true);y.empty();y.append($("<div class='first last column' style='width:98%; padding: 3px; float: left;'></div>"));$col=y.children().eq(y.children().length-1);$destroyable=A.clone();if(E.overflow){targetHeight=E.overflow.height;columnize($col,$destroyable,$col,targetHeight);if(!$destroyable.children().find(":first-child").hasClass("dontend")){split($col,$destroyable,$col,targetHeight)}while(checkDontEndColumn($col.children(":last").get(0))){var a=$col.children(":last");a.remove();$destroyable.prepend(a)}var b="";var c=document.createElement('DIV');while($destroyable[0].childNodes.length>0){var d=$destroyable[0].childNodes[0];for(var i=0;i<d.attributes.length;i++){if(d.attributes[i].nodeName.indexOf("jQuery")==0){d.removeAttribute(d.attributes[i].nodeName)}}c.innerHTML="";c.appendChild($destroyable[0].childNodes[0]);b+=c.innerHTML}var e=$(E.overflow.id)[0];e.innerHTML=b}else{$col.append($destroyable)}y.data("columnizing",false);if(E.overflow){E.overflow.doneFunc()}}function checkDontEndColumn(a){if(a!=undefined){if(a.nodeType!=1)return false;if($(a).hasClass("dontend"))return true;if(a.childNodes.length==0)return false;return checkDontEndColumn(a.childNodes[a.childNodes.length-1])}}function columnizeIt(){if(B==y.width())return;B=y.width();var c=Math.round(y.width()/E.width);if(E.columns)c=E.columns;if(c<=1){return singleColumnizeIt()}if(y.data("columnizing"))return;y.data("columnized",true);y.data("columnizing",true);y.empty();y.append($("<div style='width:"+(Math.round(100/c)-2)+"%; padding: 3px; float: left;'></div>"));m=y.children(":last");m.append(A.clone());z=m.height();y.empty();var d=z/c;var e=true;var f=3;var g=false;if(E.overflow){f=1;d=E.overflow.height}else if(E.height&&E.width){f=1;d=E.height;g=true}for(var j=0;j<f;j++){y.empty();var k=A.clone();k.css("visibility","hidden");for(var i=0;i<c;i++){var l=(i==0)?"first column":"column";var l=(i==c-1)?("last "+l):l;y.append($("<div class='"+l+"' style='width:"+(Math.round(100/c)-2)+"%; float: left;'></div>"))}var i=0;while(i<c-(E.overflow?0:1)||g&&k.children().length){if(y.children().length<=i){y.append($("<div class='"+l+"' style='width:"+(Math.round(100/c)-2)+"%; float: left;'></div>"))}var m=y.children().eq(i);columnize(m,k,m,d);if(!k.children().find(":first-child").hasClass("dontend")){split(m,k,m,d)}else{}while(checkDontEndColumn(m.children(":last").get(0))){var n=m.children(":last");n.remove();k.prepend(n)}i++}if(E.overflow&&!g){var o="";var p=document.createElement('DIV');while(k[0].childNodes.length>0){var q=k[0].childNodes[0];for(var i=0;i<q.attributes.length;i++){if(q.attributes[i].nodeName.indexOf("jQuery")==0){q.removeAttribute(q.attributes[i].nodeName)}}p.innerHTML="";p.appendChild(k[0].childNodes[0]);o+=p.innerHTML}var r=$(E.overflow.id)[0];r.innerHTML=o}else if(!g){m=y.children().eq(y.children().length-1);while(k.children().length)m.append(k.children(":first"));var s=m.height();var t=s-d;var u=0;var v=10000000;var w=0;y.children().each(function(b){return function(a){var h=b.children().eq(a).height();u+=h;if(h>w)w=h;if(h<v)v=h}}(y));var x=u/c;if(w-v>30){d=x+30}else if(Math.abs(x-d)>20){d=x}else{j=f}}else{y.children().each(function(i){m=y.children().eq(i);m.width(E.width+"px");if(i==0){m.addClass("first")}else if(i==y.children().length-1){m.addClass("last")}else{m.removeClass("first");m.removeClass("last")}});y.width(y.children().length*E.width+"px")}y.append($("<br style='clear:both;'>"))}y.find('.column').find(':first.removeiffirst').remove();y.find('.column').find(':last.removeiflast').remove();y.data("columnizing",false);if(E.overflow){E.overflow.doneFunc()}}})}})(jQuery);