(function(a){a.scrollingParallax=function(l,e){var e=e||{};e.enableVertical=typeof(e.enableVertical)!="undefined"?e.enableVertical:true;if(e.enableVertical){e.staticSpeed=e.staticSpeed||false;e.staticScrollLimit=typeof(e.staticScrollLimit)!="undefined"?e.staticScrollLimit:true;e.loopIt=e.loopIt||false;e.reverseDirection=e.reverseDirection||false}e.enableHorizontal=e.enableHorizontal||false;if(e.enableHorizontal){e.staticSpeedX=e.staticSpeedX||false;e.staticScrollLimitX=typeof(e.staticScrollLimitX)!="undefined"?e.staticScrollLimitX:true;e.loopItX=e.loopItX||false;e.reverseDirectionX=e.reverseDirectionX||false}e.disableIE6=e.disableIE6||false;e.disableIE6Anim=typeof(e.disableIE6Anim)!="undefined"?e.disableIE6Anim:true;e.bgWidth=e.bgWidth||(e.enableHorizontal?"150%":"100%");e.bgHeight=e.bgHeight||"150%";e.bgRepeat=e.bgRepeat||false;e.appendInFront=e.appendInFront||false;e.parallaxHeight=e.parallaxHeight||false;e.parallaxWidth=e.parallaxWidth||false;var s=a.browser.msie&&a.browser.version<7?true:false;if(e.disableIE6&&s){return false}var D=a(document);var q=a(window);var z;var y=false;if(e.enableVertical){var j;var m;var f;var r;var F=0;var p=0;var g=0;var x=false;var n=null}if(e.enableHorizontal){var k;var E;var i;var h;var o=0;var u=0;var d=0;var B=false;var w=null}v(l);function v(G){if(typeof(G)=="string"){z=t(G)}else{z=a(G);z.css("position",s?"absolute":"fixed");if(e.enableVertical){g=parseInt(z.css("top"))}if(e.enableHorizontal){d=parseInt(z.css("left"))}}if(e.disableIE6Anim&&s){return false}c();if(y){if(e.reverseDirection&&e.enableVertical){g+=-1*r;z.css("top",g)}if(e.reverseDirectionX&&e.enableHorizontal){d+=-1*h;z.css("left",d)}}q.scroll(function(){A()});q.resize(function(){c()})}function t(G){var H={display:"block",top:0,left:0,width:e.bgWidth,height:e.bgHeight,zIndex:0};H.position=s?"absolute":"fixed";if(e.bgRepeat){var I=e.appendInFront?a("<div></div>").appendTo(a("body")):a("<div></div>").prependTo(a("body"));H.backgroundRepeat="repeat";H.backgroundImage='url("'+G+'")'}else{var I=e.appendInFront?a("<img />").appendTo(a("body")):a("<img />").prependTo(a("body"));I.attr("src",G)}I.css(H);y=true;return I}function c(){if(e.enableVertical){j=z.height();m=q.height();f=D.height();r=(e.parallaxHeight||j)-m;if(r<0){if(e.staticSpeed){r=m-j}else{r=e.reverseDirection?m-g-j:g}x=true}if(s&&!F){F=-1*(f-j)}if(e.loopIt){p=parseInt(D.scrollTop()/(x?m:j))}}if(e.enableHorizontal){k=z.width();E=q.width();i=D.width();h=(e.parallaxWidth||k)-E;if(h<0){h=e.staticSpeedX?E-k:e.reverseDirectionX?E-d-k:d;B=true}if(s&&!o){o=-1*(i-k)}if(e.loopItX){u=parseInt(D.scrollLeft()/(B?E:k))}}A()}function A(){z.queue([]);var I={};if(e.enableVertical){var H=C(true);I.top=H}if(e.enableHorizontal){var G=C(false);I.left=G}if(!a.browser.msie&&(Math.abs(n-H)>100||Math.abs(w-G)>100)){z.animate(I,30)}else{z.css(I)}n=H;w=G}function C(M){if(M){var N=D.scrollTop();var S=f;var Q=m;var L=j;var J=r;var I=p;var O=g;var J=r;var R=x;var P=F;var G={reverseDirection:e.reverseDirection,staticSpeed:e.staticSpeed,loopIt:e.loopIt,staticScrollLimit:e.staticScrollLimit}}else{var N=D.scrollLeft();var S=i;var Q=E;var L=k;var I=u;var O=d;var J=h;var R=B;var P=o;var G={reverseDirection:e.reverseDirectionX,staticSpeed:e.staticSpeedX,loopIt:e.loopItX,staticScrollLimit:e.staticScrollLimitX}}if(G.staticSpeed){var K=N*G.staticSpeed;K-=J*(I)}else{var H=N/(S-Q);var K=H*J}if(!G.reverseDirection){K*=-1}K+=O;if(G.staticSpeed){K=b(K,M,G,J,R)}if(R&&G.staticSpeed&&G.loopIt){K+=Q-L}if(s){K+=N;K=Math.max(parseInt(K),parseInt(P))}return K}function b(H,J,K,G,I){if(!K.loopIt){if(K.staticScrollLimit){if(I){if(H<0){H=0}if(H>G){H=G}}else{if(H>0){H=0}if(-1*H>G){H=-1*G}}}}else{while(H<G){H+=G;var L=K.reverseDirection?-1:1;if(J){p+=L}else{u+=L}}while(H>(K.reverseDirection?-1:0)){H-=G;var L=K.reverseDirection?-1:1;if(J){p-=L}else{u-=L}}}return H}};a.fn.scrollingParallax=function(b){this.each(function(){new a.scrollingParallax(this,b)});return this}})(jQuery);
