/*
* Cube Portfolio - Responsive jQuery Grid Plugin
*
* version: 4.3.0 (9 August, 2017)
* require: jQuery v1.8+
*
* Copyright 2013-2017, Mihai Buricea (http://scriptpie.com/cubeportfolio/live-preview/)
* Licensed under CodeCanyon License (http://codecanyon.net/licenses)
*
*/
!function(e,t,n,o){"use strict";function i(t,n,a){var r=this;if(e.data(t,"cubeportfolio"))throw new Error("cubeportfolio is already initialized. Destroy it before initialize again!");r.obj=t,r.$obj=e(t),e.data(r.obj,"cubeportfolio",r),n.sortToPreventGaps!==o&&(n.sortByDimension=n.sortToPreventGaps,delete n.sortToPreventGaps),r.options=e.extend({},e.fn.cubeportfolio.options,n,r.$obj.data("cbp-options")),r.isAnimating=!0,r.defaultFilter=r.options.defaultFilter,r.registeredEvents=[],r.queue=[],r.addedWrapp=!1,e.isFunction(a)&&r.registerEvent("initFinish",a,!0);var s=r.$obj.children();r.$obj.addClass("cbp"),(0===s.length||s.first().hasClass("cbp-item"))&&(r.wrapInner(r.obj,"cbp-wrapper"),r.addedWrapp=!0),r.$ul=r.$obj.children().addClass("cbp-wrapper"),r.wrapInner(r.obj,"cbp-wrapper-outer"),r.wrapper=r.$obj.children(".cbp-wrapper-outer"),r.blocks=r.$ul.children(".cbp-item"),r.blocksOn=r.blocks,r.wrapInner(r.blocks,"cbp-item-wrapper"),r.plugins={},e.each(i.plugins,function(e,t){var n=t(r);n&&(r.plugins[e]=n)}),r.triggerEvent("afterPlugins"),r.removeAttrAfterStoreData=e.Deferred(),r.loadImages(r.$obj,r.display)}e.extend(i.prototype,{storeData:function(t,n){var o=this;n=n||0,t.each(function(t,i){var a=e(i),r=a.width(),s=a.height();a.data("cbp",{index:n+t,indexInitial:n+t,wrapper:a.children(".cbp-item-wrapper"),widthInitial:r,heightInitial:s,width:r,height:s,widthAndGap:r+o.options.gapVertical,heightAndGap:s+o.options.gapHorizontal,left:null,leftNew:null,top:null,topNew:null,pack:!1})}),this.removeAttrAfterStoreData.resolve()},wrapInner:function(e,t){var i,a,r;if(t=t||"",!(e.length&&e.length<1))for(e.length===o&&(e=[e]),a=e.length-1;a>=0;a--){for(i=e[a],(r=n.createElement("div")).setAttribute("class",t);i.childNodes.length;)r.appendChild(i.childNodes[0]);i.appendChild(r)}},removeAttrImage:function(e){this.removeAttrAfterStoreData.then(function(){e.removeAttribute("width"),e.removeAttribute("height"),e.removeAttribute("style")})},loadImages:function(t,n){var o=this;requestAnimationFrame(function(){var i=t.find("img").map(function(t,n){if(n.hasAttribute("width")&&n.hasAttribute("height")){if(n.style.width=n.getAttribute("width")+"px",n.style.height=n.getAttribute("height")+"px",n.hasAttribute("data-cbp-src"))return null;if(null===o.checkSrc(n))o.removeAttrImage(n);else{var i=e("
");i.on("load.cbp error.cbp",function(){e(this).off("load.cbp error.cbp"),o.removeAttrImage(n)}),n.srcset?(i.attr("sizes",n.sizes||"100vw"),i.attr("srcset",n.srcset)):i.attr("src",n.src)}return null}return o.checkSrc(n)}),a=i.length;0!==a?e.each(i,function(t,i){var r=e("
");r.on("load.cbp error.cbp",function(){e(this).off("load.cbp error.cbp"),0===--a&&n.call(o)}),i.srcset?(r.attr("sizes",i.sizes),r.attr("srcset",i.srcset)):r.attr("src",i.src)}):n.call(o)})},checkSrc:function(t){var n=t.srcset,i=t.src;if(""===i)return null;var a=e("
");n?(a.attr("sizes",t.sizes||"100vw"),a.attr("srcset",n)):a.attr("src",i);var r=a[0];return r.complete&&r.naturalWidth!==o&&0!==r.naturalWidth?null:r},display:function(){var e=this;e.width=e.$obj.outerWidth(),e.triggerEvent("initStartRead"),e.triggerEvent("initStartWrite"),e.width>0&&(e.storeData(e.blocks),e.layoutAndAdjustment()),e.triggerEvent("initEndRead"),e.triggerEvent("initEndWrite"),e.$obj.addClass("cbp-ready"),e.runQueue("delayFrame",e.delayFrame)},delayFrame:function(){var e=this;requestAnimationFrame(function(){e.resizeEvent(),e.triggerEvent("initFinish"),e.isAnimating=!1,e.$obj.trigger("initComplete.cbp")})},resizeEvent:function(){var e=this;i["private"].resize.initEvent({instance:e,fn:function(){e.triggerEvent("beforeResizeGrid");var t=e.$obj.outerWidth();e.width!==t&&(e.width=t,"alignCenter"===e.options.gridAdjustment&&(e.wrapper[0].style.maxWidth=""),e.layoutAndAdjustment(),e.triggerEvent("resizeGrid")),e.triggerEvent("resizeWindow")}})},gridAdjust:function(){var t=this;"responsive"===t.options.gridAdjustment?t.responsiveLayout():(t.blocks.removeAttr("style"),t.blocks.each(function(n,o){var i=e(o).data("cbp"),a=o.getBoundingClientRect(),r=t.columnWidthTruncate(a.right-a.left),s=Math.round(a.bottom-a.top);i.height=s,i.heightAndGap=s+t.options.gapHorizontal,i.width=r,i.widthAndGap=r+t.options.gapVertical}),t.widthAvailable=t.width+t.options.gapVertical),t.triggerEvent("gridAdjust")},layoutAndAdjustment:function(e){var t=this;e&&(t.width=t.$obj.outerWidth()),t.gridAdjust(),t.layout()},layout:function(){var t=this;t.computeBlocks(t.filterConcat(t.defaultFilter)),"slider"===t.options.layoutMode?(t.sliderLayoutReset(),t.sliderLayout()):(t.mosaicLayoutReset(),t.mosaicLayout()),t.blocksOff.addClass("cbp-item-off"),t.blocksOn.removeClass("cbp-item-off").each(function(t,n){var o=e(n).data("cbp");o.left=o.leftNew,o.top=o.topNew,n.style.left=o.left+"px",n.style.top=o.top+"px"}),t.resizeMainContainer()},computeFilter:function(e){var t=this;t.computeBlocks(e),t.mosaicLayoutReset(),t.mosaicLayout(),t.filterLayout()},filterLayout:function(){var t=this;t.blocksOff.addClass("cbp-item-off"),t.blocksOn.removeClass("cbp-item-off").each(function(t,n){var o=e(n).data("cbp");o.left=o.leftNew,o.top=o.topNew,n.style.left=o.left+"px",n.style.top=o.top+"px"}),t.resizeMainContainer(),t.filterFinish()},filterFinish:function(){var e=this;e.isAnimating=!1,e.$obj.trigger("filterComplete.cbp"),e.triggerEvent("filterFinish")},computeBlocks:function(e){var t=this;t.blocksOnInitial=t.blocksOn,t.blocksOn=t.blocks.filter(e),t.blocksOff=t.blocks.not(e),t.triggerEvent("computeBlocksFinish",e)},responsiveLayout:function(){var t=this;t.cols=t[e.isArray(t.options.mediaQueries)?"getColumnsBreakpoints":"getColumnsAuto"](),t.columnWidth=t.columnWidthTruncate((t.width+t.options.gapVertical)/t.cols),t.widthAvailable=t.columnWidth*t.cols,"mosaic"===t.options.layoutMode&&t.getMosaicWidthReference(),t.blocks.each(function(n,o){var i,a=e(o).data("cbp"),r=1;"mosaic"===t.options.layoutMode&&(r=t.getColsMosaic(a.widthInitial)),i=t.columnWidth*r-t.options.gapVertical,o.style.width=i+"px",a.width=i,a.widthAndGap=i+t.options.gapVertical,o.style.height=""});var n=[];t.blocks.each(function(t,o){e.each(e(o).find("img").filter("[width][height]"),function(t,o){var i=0;e(o).parentsUntil(".cbp-item").each(function(t,n){var o=e(n).width();if(o>0)return i=o,!1});var a=parseInt(o.getAttribute("width"),10),r=parseInt(o.getAttribute("height"),10),s=parseFloat((a/r).toFixed(10));n.push({el:o,width:i,height:Math.round(i/s)})})}),e.each(n,function(e,t){t.el.width=t.width,t.el.height=t.height,t.el.style.width=t.width+"px",t.el.style.height=t.height+"px"}),t.blocks.each(function(n,o){var i=e(o).data("cbp"),a=o.getBoundingClientRect(),r=Math.round(a.bottom-a.top);i.height=r,i.heightAndGap=r+t.options.gapHorizontal})},getMosaicWidthReference:function(){var t=this,n=[];t.blocks.each(function(t,o){var i=e(o).data("cbp");n.push(i.widthInitial)}),n.sort(function(e,t){return e-t}),n[0]?t.mosaicWidthReference=n[0]:t.mosaicWidthReference=t.columnWidth},getColsMosaic:function(e){var t=this;if(e===t.width)return t.cols;var n=e/t.mosaicWidthReference;return n=n%1>=.79?Math.ceil(n):Math.floor(n),Math.min(Math.max(n,1),t.cols)},getColumnsAuto:function(){var e=this;if(0===e.blocks.length)return 1;var t=e.blocks.first().data("cbp").widthInitial+e.options.gapVertical;return Math.max(Math.round(e.width/t),1)},getColumnsBreakpoints:function(){var t,n=this,o=n.width;return e.each(n.options.mediaQueries,function(e,n){if(o>=n.width)return t=n,!1}),t||(t=n.options.mediaQueries[n.options.mediaQueries.length-1]),n.triggerEvent("onMediaQueries",t.options),t.cols},columnWidthTruncate:function(e){return Math.floor(e)},resizeMainContainer:function(){var t,n=this,a=Math.max(n.freeSpaces.slice(-1)[0].topStart-n.options.gapHorizontal,0);"alignCenter"===n.options.gridAdjustment&&(t=0,n.blocksOn.each(function(n,o){var i=e(o).data("cbp"),a=i.left+i.width;a>t&&(t=a)}),n.wrapper[0].style.maxWidth=t+"px"),a!==n.height?(n.obj.style.height=a+"px",n.height!==o&&(i["private"].modernBrowser?n.$obj.one(i["private"].transitionend,function(){n.$obj.trigger("pluginResize.cbp")}):n.$obj.trigger("pluginResize.cbp")),n.height=a,n.triggerEvent("resizeMainContainer")):n.triggerEvent("resizeMainContainer")},filterConcat:function(e){return e.replace(/\|/gi,"")},pushQueue:function(e,t){var n=this;n.queue[e]=n.queue[e]||[],n.queue[e].push(t)},runQueue:function(t,n){var o=this,i=o.queue[t]||[];e.when.apply(e,i).then(e.proxy(n,o))},clearQueue:function(e){this.queue[e]=[]},registerEvent:function(e,t,n){var o=this;o.registeredEvents[e]||(o.registeredEvents[e]=[]),o.registeredEvents[e].push({func:t,oneTime:n||!1})},triggerEvent:function(e,t){var n,o,i=this;if(i.registeredEvents[e])for(n=0,o=i.registeredEvents[e].length;n0?(n=null,!1):null===n&&void 0}),n},generateF1F2:function(e,t){var n=this,o=n.freeSpaces[e],i={leftStart:o.leftStart+t.widthAndGap,leftEnd:o.leftEnd,topStart:o.topStart,topEnd:o.topEnd},a={leftStart:o.leftStart,leftEnd:o.leftEnd,topStart:o.topStart+t.heightAndGap,topEnd:o.topEnd};n.freeSpaces.splice(e,1),i.leftEnd>i.leftStart&&i.topEnd>i.topStart&&(n.freeSpaces.splice(e,0,i),e++),a.leftEnd>a.leftStart&&a.topEnd>a.topStart&&n.freeSpaces.splice(e,0,a)},generateG1G2G3G4:function(t){var n=this,o=[];e.each(n.freeSpaces,function(e,i){var a=n.intersectSpaces(i,t);null!==a?(n.generateG1(i,a,o),n.generateG2(i,a,o),n.generateG3(i,a,o),n.generateG4(i,a,o)):o.push(i)}),n.freeSpaces=o},intersectSpaces:function(e,t){var n={leftStart:t.leftNew,leftEnd:t.leftNew+t.widthAndGap,topStart:t.topNew,topEnd:t.topNew+t.heightAndGap};if(e.leftStart===n.leftStart&&e.leftEnd===n.leftEnd&&e.topStart===n.topStart&&e.topEnd===n.topEnd)return null;var o=Math.max(e.leftStart,n.leftStart),i=Math.min(e.leftEnd,n.leftEnd),a=Math.max(e.topStart,n.topStart),r=Math.min(e.topEnd,n.topEnd);return i<=o||r<=a?null:{leftStart:o,leftEnd:i,topStart:a,topEnd:r}},generateG1:function(e,t,n){e.topStart!==t.topStart&&n.push({leftStart:e.leftStart,leftEnd:e.leftEnd,topStart:e.topStart,topEnd:t.topStart})},generateG2:function(e,t,n){e.leftEnd!==t.leftEnd&&n.push({leftStart:t.leftEnd,leftEnd:e.leftEnd,topStart:e.topStart,topEnd:e.topEnd})},generateG3:function(e,t,n){e.topEnd!==t.topEnd&&n.push({leftStart:e.leftStart,leftEnd:e.leftEnd,topStart:t.topEnd,topEnd:e.topEnd})},generateG4:function(e,t,n){e.leftStart!==t.leftStart&&n.push({leftStart:e.leftStart,leftEnd:t.leftStart,topStart:e.topStart,topEnd:e.topEnd})},cleanFreeSpaces:function(){var e=this;e.freeSpaces.sort(function(e,t){return e.topStart>t.topStart?1:e.topStartt.leftStart?1:e.leftStart=n.leftEnd&&t.topStart<=n.topStart&&t.topEnd>=n.topEnd?(n=null,!1):void 0}),n})},uniqueFreeSpaces:function(){var t=this,n=[];e.each(t.freeSpaces,function(t,o){e.each(n,function(e,t){if(t.leftStart===o.leftStart&&t.leftEnd===o.leftEnd&&t.topStart===o.topStart&&t.topEnd===o.topEnd)return o=null,!1}),null!==o&&n.push(o)}),t.freeSpaces=n},addHeightToBlocks:function(){var t=this;e.each(t.freeSpaces,function(n,o){t.blocksOn.each(function(n,i){var a=e(i).data("cbp");!0===a.pack&&t.intersectSpaces(o,a)&&-1===o.topStart-a.topNew-a.heightAndGap&&(i.style.height=a.height-1+"px")})})},sortBlocks:function(t,n,o,i){o=void 0===o?"leftNew":o,i=void 0===i?1:-1,t.sort(function(t,a){var r=e(t).data("cbp"),s=e(a).data("cbp");return r[n]>s[n]?i:r[n]s[o]?i:r[o]s.index?i:r.index