(function(c){
/*
     * smartresize: debounced resize event for jQuery
     * http://github.com/lrbabe/jquery-smartresize
     *
     * Copyright (c) 2009 Louis-Remi Babe
     * Licensed under the GPL license.
     * http://docs.jquery.com/License
     *
     */
var b=c.event,a;b.special.smartresize={setup:function(){c(this).bind("resize",b.special.smartresize.handler)},teardown:function(){c(this).unbind("resize",b.special.smartresize.handler)},handler:function(g,d){var f=this,e=arguments;g.type="smartresize";if(a){clearTimeout(a)}a=setTimeout(function(){jQuery.event.handle.apply(f,e)},d==="execAsap"?0:100)}};c.fn.smartresize=function(d){return d?this.bind("smartresize",d):this.trigger("smartresize",["execAsap"])};c.fn.masonry=function(e,l){function h(m,n){m.$bricks=n.itemSelector==undefined?n.$brickParent.children():n.$brickParent.find(n.itemSelector)}function g(n,r,s,t,p,q){var o=0;for(i=0;i<r;i++){if(s[i]<s[o]){o=i}}var m={left:p.colW*o+p.posLeft,top:s[o]};if(p.masoned&&q.animate){n.animate(m,{duration:q.animationOptions.duration,easing:q.animationOptions.easing,complete:q.animationOptions.complete,step:q.animationOptions.step,queue:q.animationOptions.queue,specialEasing:q.animationOptions.specialEasing})}else{n.css(m)}for(i=0;i<t;i++){p.colY[o+i]=s[o]+n.outerHeight(true)}}function d(o,n,m){h(m,n);if(n.columnWidth==undefined){m.colW=m.masoned?o.data("masonry").colW:m.$bricks.outerWidth(true)}else{m.colW=n.columnWidth}m.colCount=Math.floor(o.width()/m.colW);m.colCount=Math.max(m.colCount,1)}function k(p,o,n){if(!n.masoned){p.css("position","relative")}if(!n.masoned||o.appendedContent!=undefined){n.$bricks.css("position","absolute")}var q=c("<div />");p.prepend(q);n.posTop=Math.round(q.position().top);n.posLeft=Math.round(q.position().left);q.remove();if(n.masoned&&o.appendedContent!=undefined){n.colY=p.data("masonry").colY;for(i=p.data("masonry").colCount;i<n.colCount;i++){n.colY[i]=n.posTop}}else{n.colY=[];for(i=0;i<n.colCount;i++){n.colY[i]=n.posTop}}if(o.singleMode){n.$bricks.each(function(){var r=c(this);g(r,n.colCount,n.colY,1,n,o)})}else{n.$bricks.each(function(){var r=c(this);var t=Math.ceil(r.outerWidth(true)/n.colW);t=Math.min(t,n.colCount);if(t==1){g(r,n.colCount,n.colY,1,n,o)}else{var u=n.colCount+1-t;var s=[0];for(i=0;i<u;i++){s[i]=0;for(j=0;j<t;j++){s[i]=Math.max(s[i],n.colY[i+j])}}g(r,u,s,t,n,o)}})}n.wallH=0;for(i=0;i<n.colCount;i++){n.wallH=Math.max(n.wallH,n.colY[i])}var m={height:n.wallH-n.posTop};if(n.masoned&&o.animate){p.animate(m,{duration:o.animationOptions.duration,easing:o.animationOptions.easing,complete:o.animationOptions.complete,step:o.animationOptions.step,queue:o.animationOptions.queue,specialEasing:o.animationOptions.specialEasing})}else{p.css(m)}if(!n.masoned){p.addClass("masoned")}l.call(n.$bricks);p.data("masonry",n)}function f(p,o,n){n.masoned=p.data("masonry")!=undefined;var m=p.data("masonry").colCount;d(p,o,n);if(n.colCount!=m){k(p,o,n)}}return this.each(function(){var q=c(this);var o=c.extend({},c.masonry);o.masoned=q.data("masonry")!=undefined;var n=o.masoned?q.data("masonry").options:{};var p=c.extend({},o.defaults,n,e);o.options=p.saveOptions?p:n;l=l||function(){};if(o.masoned&&p.appendedContent!=undefined){p.$brickParent=p.appendedContent}else{p.$brickParent=q}h(o,p);if(o.$bricks.length){d(q,p,o);k(q,p,o);var m=n.resizeable;if(!m&&p.resizeable){c(window).bind("smartresize.masonry",function(){f(q,p,o)})}if(m&&!p.resizeable){c(window).unbind("smartresize.masonry")}}else{return this}})};c.masonry={defaults:{singleMode:false,columnWidth:undefined,itemSelector:undefined,appendedContent:undefined,saveOptions:true,resizeable:true,animate:false,animationOptions:{}},colW:undefined,colCount:undefined,colY:undefined,wallH:undefined,masoned:undefined,posTop:0,posLeft:0,options:undefined,$bricks:undefined,$brickParent:undefined}})(jQuery);