function extend(a,b){for(var key in b){if(b.hasOwnProperty(key)){a[key]=b[key];}}return a;}function debounce(func,wait,immediate){var timeout;return function(){var context=this,args=arguments;var later=function(){timeout=null;if(!immediate)func.apply(context,args);};var callNow=immediate&&!timeout;clearTimeout(timeout);timeout=setTimeout(later,wait);if(callNow)func.apply(context,args);};};function areClipPathShapesSupported(){var base='clipPath',prefixes=['webkit','moz','ms','o'],properties=[base],testElement=document.createElement('testelement'),attribute='polygon(50% 0%, 0% 100%, 100% 100%)';for(var i=0,l=prefixes.length;i<l;i++){var prefixedProperty=prefixes[i]+base.charAt(0).toUpperCase()+base.slice(1);properties.push(prefixedProperty);}for(var i=0,l=properties.length;i<l;i++){var property=properties[i];if(testElement.style[property]===''){testElement.style[property]=attribute;if(testElement.style[property]!==''){return true;}}}return false;};function getMousePos(e){var posx=0,posy=0;if(!e)var e=window.event;if(e.pageX||e.pageY){posx=e.pageX;posy=e.pageY;}else if(e.clientX||e.clientY){posx=e.clientX+document.body.scrollLeft+document.documentElement.scrollLeft;posy=e.clientY+document.body.scrollTop+document.documentElement.scrollTop;}return{x:posx,y:posy}}function getRandom(min,max){return Math.random()*(max-min+1)+min;}const isClipPathSupported=areClipPathShapesSupported();function FragmentsFx(el,options){this.el=el;this.options=extend({},this.options);extend(this.options,options);var self=this;imagesLoaded(this.el,{background:true},function(){self._init();});}FragmentsFx.prototype.options={fragments:25,boundaries:{x1:100,x2:100,y1:50,y2:50},area:'random',randomIntervals:{top:{min:0,max:90},left:{min:0,max:90},dimension:{width:{min:10,max:60,fixedHeight:1.1},height:{min:10,max:60,fixedWidth:1.1}}},parallax:false,randomParallax:{min:10,max:150}};FragmentsFx.prototype._init=function(){this.dimensions={width:this.el.offsetWidth,height:this.el.offsetHeight};this.imgsrc=this.el.style.backgroundImage.replace('url(','').replace(')','').replace(/\"/gi,"");this._layout();this._initEvents();};FragmentsFx.prototype._initEvents=function(){const self=this;if(this.options.parallax){this.mousemoveFn=function(ev){requestAnimationFrame(function(){const mousepos=getMousePos(ev),docScrolls={left:document.body.scrollLeft+document.documentElement.scrollLeft,top:document.body.scrollTop+document.documentElement.scrollTop},bounds=self.el.getBoundingClientRect(),relmousepos={x:mousepos.x-bounds.left-docScrolls.left,y:mousepos.y-bounds.top-docScrolls.top};for(var i=0,len=self.fragments.length;i<=len-1;++i){const fragment=self.fragments[i],t=fragment.getAttribute('data-parallax'),transX=t/(self.dimensions.width)*relmousepos.x-t/2,transY=t/(self.dimensions.height)*relmousepos.y-t/2;fragment.style.transform=fragment.style.WebkitTransform='translate3d('+transX+'px,'+transY+'px,0)';}});};this.el.addEventListener('mousemove',this.mousemoveFn);this.mouseleaveFn=function(ev){requestAnimationFrame(function(){for(var i=0,len=self.fragments.length;i<=len-1;++i){const fragment=self.fragments[i];fragment.style.transform=fragment.style.WebkitTransform='translate3d(0,0,0)';}});};this.el.addEventListener('mouseleave',this.mouseleaveFn);}this.debounceResize=debounce(function(ev){const areasTotal=self.options.area.length;self.dimensions={width:self.el.offsetWidth,height:self.el.offsetHeight};for(var i=0,len=self.fragments.length;i<=len-1;++i){self._positionFragment(i,self.fragments[i].querySelector('.fragment__piece'));}},10);window.addEventListener('resize',this.debounceResize);};FragmentsFx.prototype._layout=function(){this.fragments=[];for(var i=0,len=this.options.fragments;i<len;++i){const fragment=this._createFragment(i);this.fragments.push(fragment);}};FragmentsFx.prototype._createFragment=function(pos){var fragment=document.createElement('div');fragment.className='fragment';if(this.options.parallax){fragment.setAttribute('data-parallax',getRandom(this.options.randomParallax.min,this.options.randomParallax.max));}var piece=document.createElement('div');piece.style.backgroundImage='url('+this.imgsrc+')';piece.className='fragment__piece';piece.style.backgroundImage='url('+this.imgsrc+')';this._positionFragment(pos,piece);fragment.appendChild(piece);this.el.appendChild(fragment);return fragment;};FragmentsFx.prototype._positionFragment=function(pos,piece){const isRandom=this.options.area==='random',data=this.options.area[pos],top=isRandom?getRandom(this.options.randomIntervals.top.min,this.options.randomIntervals.top.max):data.top,left=isRandom?getRandom(this.options.randomIntervals.left.min,this.options.randomIntervals.left.max):data.left;var width,height;if(isRandom){if(!!Math.round(getRandom(0,1))){width=getRandom(this.options.randomIntervals.dimension.width.min,this.options.randomIntervals.dimension.width.max);height=getRandom(Math.max(this.options.randomIntervals.dimension.width.fixedHeight-0.1,0.1),this.options.randomIntervals.dimension.width.fixedHeight+0.1);}else{height=getRandom(this.options.randomIntervals.dimension.width.min,this.options.randomIntervals.dimension.width.max);width=getRandom(Math.max(this.options.randomIntervals.dimension.height.fixedWidth-0.1,0.1),this.options.randomIntervals.dimension.height.fixedWidth+0.1);}}else{width=data.width;height=data.height;}if(!isClipPathSupported){const clipTop=top/100*this.dimensions.height,clipLeft=left/100*this.dimensions.width,clipRight=width/100*this.dimensions.width+clipLeft,clipBottom=height/100*this.dimensions.height+clipTop;piece.style.clip='rect('+clipTop+'px,'+clipRight+'px,'+clipBottom+'px,'+clipLeft+'px)';}else{piece.style.WebkitClipPath=piece.style.clipPath='polygon('+left+'% '+top+'%, '+(left+width)+'% '+top+'%, '+(left+width)+'% '+(top+height)+'%, '+left+'% '+(top+height)+'%)';}const translation={x:getRandom(-1*left/100*this.dimensions.width-this.options.boundaries.x1,this.dimensions.width-left/100*this.dimensions.width+this.options.boundaries.x2-width/100*this.dimensions.width),y:getRandom(-1*top/100*this.dimensions.height-this.options.boundaries.y1,this.dimensions.height-top/100*this.dimensions.height+this.options.boundaries.y2-height/100*this.dimensions.height)};piece.style.WebkitTransform=piece.style.transform='translate3d('+translation.x+'px,'+translation.y+'px,0)';};window.FragmentsFx=FragmentsFx;