/*! waterfall - v0.1.73 - 2015-12-01
* http://wlog.cn/waterfall/
* Copyright (c) 2015 bingdian; Licensed MIT */
!function($,window){"use strict";var $window=$(window),defaults={itemCls:"waterfall-item",prefix:"waterfall",fitWidth:!0,colWidth:296,gutterWidth:10,gutterHeight:10,align:"center",minCol:1,maxCol:undefined,maxPage:undefined,bufferPixel:-50,containerStyle:{position:"relative"},resizable:!0,isFadeIn:!1,isAnimated:!1,animationOptions:{},isAutoPrefill:!0,checkImagesLoaded:!0,path:undefined,dataType:"json",params:{},headers:{},loadingMsg:'<div style="text-align:center;padding:10px 0; color:#999;"><img src="data:image/gif;base64,R0lGODlhEAALAPQAAP///zMzM+Li4tra2u7u7jk5OTMzM1hYWJubm4CAgMjIyE9PT29vb6KiooODg8vLy1JSUjc3N3Jycuvr6+Dg4Pb29mBgYOPj4/X19cXFxbOzs9XV1fHx8TMzMzMzMzMzMyH5BAkLAAAAIf4aQ3JlYXRlZCB3aXRoIGFqYXhsb2FkLmluZm8AIf8LTkVUU0NBUEUyLjADAQAAACwAAAAAEAALAAAFLSAgjmRpnqSgCuLKAq5AEIM4zDVw03ve27ifDgfkEYe04kDIDC5zrtYKRa2WQgAh+QQJCwAAACwAAAAAEAALAAAFJGBhGAVgnqhpHIeRvsDawqns0qeN5+y967tYLyicBYE7EYkYAgAh+QQJCwAAACwAAAAAEAALAAAFNiAgjothLOOIJAkiGgxjpGKiKMkbz7SN6zIawJcDwIK9W/HISxGBzdHTuBNOmcJVCyoUlk7CEAAh+QQJCwAAACwAAAAAEAALAAAFNSAgjqQIRRFUAo3jNGIkSdHqPI8Tz3V55zuaDacDyIQ+YrBH+hWPzJFzOQQaeavWi7oqnVIhACH5BAkLAAAALAAAAAAQAAsAAAUyICCOZGme1rJY5kRRk7hI0mJSVUXJtF3iOl7tltsBZsNfUegjAY3I5sgFY55KqdX1GgIAIfkECQsAAAAsAAAAABAACwAABTcgII5kaZ4kcV2EqLJipmnZhWGXaOOitm2aXQ4g7P2Ct2ER4AMul00kj5g0Al8tADY2y6C+4FIIACH5BAkLAAAALAAAAAAQAAsAAAUvICCOZGme5ERRk6iy7qpyHCVStA3gNa/7txxwlwv2isSacYUc+l4tADQGQ1mvpBAAIfkECQsAAAAsAAAAABAACwAABS8gII5kaZ7kRFGTqLLuqnIcJVK0DeA1r/u3HHCXC/aKxJpxhRz6Xi0ANAZDWa+kEAA7" alt=""><br />Loading...</div>',state:{isDuringAjax:!1,isProcessingData:!1,isResizing:!1,isPause:!1,curPage:16},callbacks:{loadingStart:function($loading){$loading.show()},loadingFinished:function($loading,isBeyondMaxPage){isBeyondMaxPage?$loading.remove():$loading.fadeOut()},loadingError:function($message,xhr){$message.html("Data load faild, please try again later.")},renderData:function(data,dataType){var tpl;return"json"===dataType||"jsonp"===dataType?(tpl=$("#waterfall-tpl").html(),Handlebars.compile(tpl)(data)):data}},debug:!1};function Waterfall(element,options){this.$element=$(element),this.options=$.extend(!0,{},defaults,options),this.colHeightArray=[],this.styleQueue=[],this._init()}Waterfall.prototype={constructor:Waterfall,_debug:function(){!0===this.options.debug&&("undefined"!=typeof console&&"function"==typeof console.log?1===Array.prototype.slice.call(arguments).length&&"string"==typeof Array.prototype.slice.call(arguments)[0]?console.log(Array.prototype.slice.call(arguments).toString()):console.log(Array.prototype.slice.call(arguments)):Function.prototype.bind||"undefined"==typeof console||"object"!=typeof console.log||Function.prototype.call.call(console.log,console,Array.prototype.slice.call(arguments)))},_init:function(callback){var options=this.options,path=options.path;this._setColumns(),this._initContainer(),this._resetColumnsHeightArray(),this.reLayout(callback),path?(options.isAutoPrefill&&this._prefill(),options.resizable&&this._doResize(),this._doScroll()):this._debug("Invalid path")},_initContainer:function(){var options=this.options,prefix=options.prefix;$("body").css({overflow:"auto"}),this.$element.css(this.options.containerStyle).addClass(prefix+"-container"),this.$element.after('<div id="'+prefix+'-loading">'+options.loadingMsg+'</div><div id="'+prefix+'-message" style="text-align:center;color:#999;"></div>'),this.$loading=$("#"+prefix+"-loading"),this.$message=$("#"+prefix+"-message")},_getColumns:function(){var options=this.options,$container=options.fitWidth?this.$element.parent():this.$element,containerWidth="BODY"===$container[0].tagName?$container.width()-20:$container.width(),colWidth=options.colWidth,gutterWidth=options.gutterWidth,minCol=options.minCol,maxCol=options.maxCol,cols=Math.floor(containerWidth/(colWidth+gutterWidth)),col=Math.max(cols,minCol);return maxCol&&col>maxCol?maxCol:col},_setColumns:function(){this.cols=this._getColumns()},_getItems:function($content){return $content.filter("."+this.options.itemCls).css({position:"absolute"})},_resetColumnsHeightArray:function(){var i,cols=this.cols;for(this.colHeightArray.length=cols,i=0;i<cols;i++)this.colHeightArray[i]=0},layout:function($content,callback){var fixMarginLeft,obj,i,j,itemsLen,styleLen,options=this.options,$items=this.options.isFadeIn?this._getItems($content).css({opacity:0}).animate({opacity:1}):this._getItems($content),styleFn=this.options.isAnimated&&this.options.state.isResizing?"animate":"css",animationOptions=options.animationOptions,colWidth=options.colWidth,gutterWidth=options.gutterWidth,len=this.colHeightArray.length,align=options.align;for(this.$element.append($items),"center"===align?fixMarginLeft=(fixMarginLeft=(this.$element.width()-colWidth*len-gutterWidth*(len-1))/2)>0?fixMarginLeft:0:"left"===align?fixMarginLeft=0:"right"===align&&(fixMarginLeft=this.$element.width()-colWidth*len-gutterWidth*(len-1)),i=0,itemsLen=$items.length;i<itemsLen;i++)this._placeItems($items[i],fixMarginLeft);for(j=0,styleLen=this.styleQueue.length;j<styleLen;j++)(obj=this.styleQueue[j]).$el[styleFn](obj.style,animationOptions);this.$element.height(Math.max.apply({},this.colHeightArray)),this.styleQueue=[],this.options.state.isResizing=!1,this.options.state.isProcessingData=!1,callback&&callback.call($items)},reLayout:function(callback){var $content=this.$element.find("."+this.options.itemCls);this._resetColumnsHeightArray(),this.layout($content,callback)},_placeItems:function(item,fixMarginLeft){var colIndex,position,$item=$(item),options=this.options,colWidth=options.colWidth,gutterWidth=options.gutterWidth,gutterHeight=options.gutterHeight,colHeightArray=this.colHeightArray,len=colHeightArray.length,minColHeight=Math.min.apply({},colHeightArray),minColIndex=$.inArray(minColHeight,colHeightArray);position={left:(colWidth+gutterWidth)*(colIndex=$item.hasClass(options.prefix+"-item-fixed-left")?0:$item.hasClass(options.prefix+"-item-fixed-right")?len>1?len-1:0:minColIndex)+fixMarginLeft,top:colHeightArray[colIndex]},this.styleQueue.push({$el:$item,style:position}),colHeightArray[colIndex]+=$item.outerHeight()+gutterHeight},prepend:function($content,callback){this.$element.prepend($content),this.reLayout(callback)},append:function($content,callback){this.$element.append($content),this.reLayout(callback)},removeItems:function($items,callback){this.$element.find($items).remove(),this.reLayout(callback)},option:function(opts,callback){$.isPlainObject(opts)&&(this.options=$.extend(!0,this.options,opts),"function"==typeof callback&&callback(),this._init())},pause:function(callback){this.options.state.isPause=!0,"function"==typeof callback&&callback()},resume:function(callback){this.options.state.isPause=!1,"function"==typeof callback&&callback()},_requestData:function(callback){var pageurl,self=this,options=this.options,curPage=(options.maxPage,options.state.curPage--),path=options.path,dataType=options.dataType,params=options.params,headers=options.headers;if(curPage<1)return options.state.isBeyondMaxPage=!0,void options.callbacks.loadingFinished(this.$loading,options.state.isBeyondMaxPage);pageurl="function"==typeof path?path(curPage):path.join(curPage),this._debug("heading into ajax",pageurl+$.param(params)),options.callbacks.loadingStart(this.$loading),options.state.isDuringAjax=!0,options.state.isProcessingData=!0,$.ajax({url:pageurl,data:params,headers:headers,dataType:dataType,success:function(data){self._handleResponse(data,callback),self.options.state.isDuringAjax=!1},error:function(jqXHR){self._responeseError("error")}})},_handleResponse:function(data,callback){var self=this,options=this.options,content=$.trim(options.callbacks.renderData(data,options.dataType)),$content=$(content);options.checkImagesLoaded?$content.imagesLoaded((function(){self.append($content,callback),self.options.callbacks.loadingFinished(self.$loading,self.options.state.isBeyondMaxPage)})):(self.append($content,callback),self.options.callbacks.loadingFinished(self.$loading,self.options.state.isBeyondMaxPage))},_responeseError:function(xhr){this.$loading.hide(),this.options.callbacks.loadingError(this.$message,xhr),"end"!==xhr&&"error"!==xhr&&(xhr="unknown"),this._debug("Error",xhr)},_nearbottom:function(){var options=this.options,minColHeight=Math.min.apply({},this.colHeightArray),distanceFromWindowBottomToMinColBottom=$window.scrollTop()+$window.height()-this.$element.offset().top-minColHeight;return this._debug("math:",distanceFromWindowBottomToMinColBottom),distanceFromWindowBottomToMinColBottom>options.bufferPixel},_prefill:function(){this.$element.height()<=$window.height()&&this._scroll()},_scroll:function(){var state=this.options.state,self=this;state.isProcessingData||state.isDuringAjax||state.isInvalidPage||state.isPause||this._nearbottom()&&this._requestData((function(){setTimeout((function(){self._scroll()}),100)}))},_doScroll:function(){var scrollTimer,self=this;$window.bind("scroll",(function(){scrollTimer&&clearTimeout(scrollTimer),scrollTimer=setTimeout((function(){self._scroll()}),100)}))},_resize:function(){var cols=this.cols,newCols=this._getColumns();newCols===cols&&"left"===this.options.align||(this.options.state.isResizing=!0,this.cols=newCols,this.reLayout(),this._prefill())},_doResize:function(){var resizeTimer,self=this;$window.bind("resize",(function(){resizeTimer&&clearTimeout(resizeTimer),resizeTimer=setTimeout((function(){self._resize()}),100)}))}},$.fn.waterfall=function(options){if("string"==typeof options){var args=Array.prototype.slice.call(arguments,1);this.each((function(){var instance=$.data(this,"plugin_waterfall");instance?$.isFunction(instance[options])&&"_"!==options.charAt(0)?instance[options].apply(instance,args):instance._debug('no such method "'+options+'"'):instance._debug("instance is not initialization")}))}else this.each((function(){$.data(this,"plugin_waterfall")||$.data(this,"plugin_waterfall",new Waterfall(this,options))}));return this}}(jQuery,window,document),function($){"use strict";var BLANK="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==";$.fn.imagesLoaded=function(callback){var $this=this,deferred=$.isFunction($.Deferred)?$.Deferred():0,hasNotify=$.isFunction(deferred.notify),$images=$this.find("img").add($this.filter("img")),loaded=[],proper=[],broken=[];function doneLoading(){var $proper=$(proper),$broken=$(broken);deferred&&(broken.length?deferred.reject($images,$proper,$broken):deferred.resolve($images)),$.isFunction(callback)&&callback.call($this,$images,$proper,$broken)}function imgLoadedHandler(event){imgLoaded(event.target,"error"===event.type)}function imgLoaded(img,isBroken){img.src!==BLANK&&-1===$.inArray(img,loaded)&&(loaded.push(img),isBroken?broken.push(img):proper.push(img),$.data(img,"imagesLoaded",{isBroken:isBroken,src:img.src}),hasNotify&&deferred.notifyWith($(img),[isBroken,$images,$(proper),$(broken)]),$images.length===loaded.length&&(setTimeout(doneLoading),$images.unbind(".imagesLoaded",imgLoadedHandler)))}return $.isPlainObject(callback)&&$.each(callback,(function(key,value){"callback"===key?callback=value:deferred&&deferred[key](value)})),$images.length?$images.bind("load.imagesLoaded error.imagesLoaded",imgLoadedHandler).each((function(i,el){var src=el.src,cached=$.data(el,"imagesLoaded");cached&&cached.src===src?imgLoaded(el,cached.isBroken):el.complete&&undefined!==el.naturalWidth?imgLoaded(el,0===el.naturalWidth||0===el.naturalHeight):(el.readyState||el.complete)&&(el.src=BLANK,el.src=src)})):doneLoading(),deferred?deferred.promise($this):$this}}(jQuery);