/*!
 * Name    : Just Another Parallax [Jarallax]
 * Version : 1.1.0
 * Author  : _nK http://nkdev.info
 * GitHub  : https://github.com/nk-o/jarallax
 */
(function(e){"function"===typeof define&&define.amd?define(["jquery"],e):"undefined"!==typeof exports?module.exports=e(require("jquery")):e(jQuery)})(function(e){Date.now||(Date.now=function(){return(new Date).getTime()});window.requestAnimationFrame||function(){for(var b=["webkit","moz"],a=0;a<b.length&&!window.requestAnimationFrame;++a){var c=b[a];window.requestAnimationFrame=window[c+"RequestAnimationFrame"];window.cancelAnimationFrame=window[c+"CancelAnimationFrame"]||window[c+"CancelRequestAnimationFrame"]}if(/iP(ad|hone|od).*OS 6/.test(window.navigator.userAgent)||
!window.requestAnimationFrame||!window.cancelAnimationFrame){var d=0;window.requestAnimationFrame=function(a){var b=Date.now(),c=Math.max(d+16,b);return setTimeout(function(){a(d=c)},c-b)};window.cancelAnimationFrame=clearTimeout}}();var l=function(){for(var b=["transform","WebkitTransform","MozTransform","OTransform","msTransform"],a=document.createElement("div"),c=0;c<b.length;c++)if(a&&void 0!==a.style[b[c]])return b[c];return!1}(),m=function(){if(!window.getComputedStyle)return!1;var b=document.createElement("p"),
a,c={webkitTransform:"-webkit-transform",OTransform:"-o-transform",msTransform:"-ms-transform",MozTransform:"-moz-transform",transform:"transform"};(document.body||document.documentElement).insertBefore(b,null);for(var d in c)void 0!==b.style[d]&&(b.style[d]="translate3d(1px,1px,1px)",a=window.getComputedStyle(b).getPropertyValue(c[d]));(document.body||document.documentElement).removeChild(b);return void 0!==a&&0<a.length&&"none"!==a}(),n=-1<navigator.userAgent.toLowerCase().indexOf("android"),p=
!!window.opera,h=[],f=function(){var b=0;return function(a,c){var d;this.$item=e(a);this.defaults={speed:.5,imgSrc:null,imgWidth:null,imgHeight:null,enableTransform:!0,zIndex:-100};d=this.$item.data("jarallax")||{};this.options=e.extend({},this.defaults,d,c);this.options.speed=Math.min(1,Math.max(0,parseFloat(this.options.speed)));this.instanceID=b++;this.image={src:this.options.imgSrc||null,$container:null,$item:null,width:this.options.imgWidth||null,height:this.options.imgHeight||null,useImgTag:n||
p};this.initImg()&&(this.init(),h.push(this))}}();f.prototype.initImg=function(){null===this.image.src&&(this.image.src=this.$item.css("background-image").replace(/^url\(['"]?/g,"").replace(/['"]?\)$/g,""));return this.image.src&&"none"!==this.image.src?!0:!1};f.prototype.init=function(){function b(){a.coverImage();a.clipContainer();a.onScroll(!0);a.$item.data("jarallax-original-styles",a.$item.attr("style"));setTimeout(function(){a.$item.css({"background-image":"none","background-attachment":"scroll",
"background-size":"auto"})},0)}var a=this,c={position:"absolute",top:0,left:0,width:"100%",height:"100%",overflow:"hidden","pointer-events":"none",transition:"transform linear -1ms, -webkit-transform linear -1ms"},d={position:"fixed"};a.image.$container=e("<div>").css(c).css({visibility:"hidden","z-index":a.options.zIndex}).attr("id","jarallax-container-"+a.instanceID).prependTo(a.$item);a.image.useImgTag&&l?(a.image.$item=e("<img>").attr("src",a.image.src),d=e.extend({"max-width":"none"},c,d)):(a.image.$item=
e("<div>"),d=e.extend({"background-position":"50% 50%","background-repeat":"no-repeat no-repeat","background-image":'url("'+a.image.src+'")'},c,d));a.image.$item.css(d).prependTo(a.image.$container);a.image.width&&a.image.height?b():a.getImageSize(a.image.src,function(c,d){a.image.width=c;a.image.height=d;b()})};f.prototype.destroy=function(){for(var b=0,a=h.length;b<a;b++)if(h[b].instanceID===this.instanceID){h.splice(b,1);break}e("head #jarallax-clip-"+this.instanceID).remove();this.$item.attr("style",
this.$item.data("jarallax-original-styles"));this.$item.removeData("jarallax-original-styles");this.image.$container.remove();delete this.$item[0].jarallax};f.prototype.round=function(b){return Math.floor(100*b)/100};f.prototype.getImageSize=function(b,a){if(!b||!a)return!1;var c=new Image;c.onload=function(){a(c.width,c.height)};c.src=b};f.prototype.clipContainer=function(){var b=this.image.$container.outerWidth(!0),a=this.image.$container.outerHeight(!0),c=e("head #jarallax-clip-"+this.instanceID);
c.length||(e("head").append('<style type="text/css" id="jarallax-clip-'+this.instanceID+'"></style>'),c=e("head #jarallax-clip-"+this.instanceID));b=["#jarallax-container-"+this.instanceID+" {","   clip: rect(0px "+b+"px "+a+"px 0);","   clip: rect(0px, "+b+"px, "+a+"px, 0);","}"].join("\n");c[0].styleSheet?c[0].styleSheet.cssText=b:c.html(b)};f.prototype.coverImage=function(){if(this.image.width&&this.image.height){var b=this.image.$container.outerWidth(!0),a=this.image.$container.outerHeight(!0),
c=e(window).outerWidth(!0),d=e(window).outerHeight(!0),g=this.image.width,f=this.image.height,d={width:Math.max(c,b)*Math.max(this.options.speed,1),height:Math.max(d,a)*Math.max(this.options.speed,1)};d.width/d.height>g/f?(c=d.width,g=d.width*f/g):(c=d.height*g/f,g=d.height);this.image.useImgTag&&l?(d.width=this.round(c),d.height=this.round(g),d.marginLeft=this.round(-(c-b)/2),d.marginTop=this.round(-(g-a)/2)):d.backgroundSize=this.round(c)+"px "+this.round(g)+"px";this.image.$item.css(d)}};f.prototype.onScroll=
function(b){if(this.image.width&&this.image.height){var a=e(window).scrollTop(),c=e(window).scrollLeft();e(window).width();var d=e(window).height(),g=this.$item.offset().top,f=this.$item.offset().left,h=this.$item.outerHeight(!0),k={visibility:"visible",backgroundPosition:"50% 50%"};(b?0:g+h<a||g>a+d)||(b=-(a-g)*this.options.speed,c=-(c-f)*this.options.speed,b=this.round(b),c=this.round(c),l&&this.options.enableTransform?(k.transform="translateY("+b+"px) translateX("+c+"px)",m&&(k.transform="translate3d("+
c+"px, "+b+"px, 0)")):k.backgroundPosition=c+"px "+b+"px",this.image.$item.css(k))}};(function(){e(window).on("scroll.jarallax",function(){window.requestAnimationFrame(function(){for(var a=0,b=h.length;a<b;a++)h[a].onScroll()})});var b;e(window).on("resize.jarallax orientationchange.jarallax load.jarallax",function(){clearTimeout(b);b=setTimeout(function(){window.requestAnimationFrame(function(){for(var a=0,b=h.length;a<b;a++){var d=h[a];d.coverImage();d.clipContainer();d.onScroll()}})},100)})})();
var q=e.fn.jarallax;e.fn.jarallax=function(){var b=arguments[0],a=Array.prototype.slice.call(arguments,1),c=this.length,d=0,e;for(d;d<c;d++)if("object"===typeof b||"undefined"===typeof b?this[d].jarallax||(this[d].jarallax=new f(this[d],b)):e=this[d].jarallax?this[d].jarallax[b].apply(this[d].jarallax,a):void 0,"undefined"!==typeof e)return e;return this};e.fn.jarallax.noConflict=function(){e.fn.jarallax=q;return this};e(document).on("ready.data-jarallax",function(){e("[data-jarallax]").jarallax()})});
