(function(n,d){var i="parallax";var o={mouseport:"body",xparallax:true,yparallax:true,xorigin:0.5,yorigin:0.5,decay:0.66,frameDuration:30,freezeClass:"freeze"},m={left:0,top:0,middle:0.5,center:0.5,right:1,bottom:1},l={px:/^\d+\s?px$/,percent:/^\d+\s?%$/},k="frame."+i,p=Math.abs,a=[0,0];function h(q){return this.lib[q]}h.lib=m;function b(q){return typeof q==="boolean"?q:!!(parseFloat(q))}function c(q){return(l.percent.exec(q))?parseFloat(q)/100:q}function g(q,s){var r=[b(q.xparallax),b(q.yparallax)];this.ontarget=false;this.decay=q.decay;this.pointer=s||[0.5,0.5];this.update=function(w,u){if(this.ontarget){this.pointer=w}else{if((!r[0]||p(w[0]-this.pointer[0])<u[0])&&(!r[1]||p(w[1]-this.pointer[1])<u[1])){this.ontarget=true;this.pointer=w}else{var v=[],t=2;while(t--){if(r[t]){v[t]=w[t]+this.decay*(this.pointer[t]-w[t])}}this.pointer=v}}}}function j(t,s){var r=this,v=t instanceof n?t:n(t),w=[b(s.xparallax),b(s.yparallax)],q=0,u;this.pointer=[0,0];this.active=false;this.activeOutside=(s&&s.activeOutside)||false;this.update=function(A){var C=this.pos,z=this.size,B=[],y=2;if(q>0){if(q===2){q=0;if(u){A=u}}while(y--){if(w[y]){B[y]=(A[y]-C[y])/z[y];B[y]=B[y]<0?0:B[y]>1?1:B[y]}}this.active=true;this.pointer=B}else{this.active=false}};this.updateSize=function(){var y=v.width(),x=v.height();r.size=[y,x];r.threshold=[1/y,1/x]};this.updatePos=function(){var z=v.offset()||{left:0,top:0},y=parseInt(v.css("borderLeftWidth"))+parseInt(v.css("paddingLeft")),x=parseInt(v.css("borderTopWidth"))+parseInt(v.css("paddingTop"));r.pos=[z.left+y,z.top+x]};n(window).bind("resize."+i,r.updateSize).bind("resize."+i,r.updatePos);v.bind("mouseenter."+i,function(x){q=1}).bind("mouseleave."+i,function(x){q=2;u=[x.pageX,x.pageY]});this.updateSize();this.updatePos()}function e(t,r){var s=[],u=[],v=[],q=[];this.update=function(A){var C=[],z,B,w=2,y={};while(w--){if(u[w]){C[w]=u[w]*A[w]+v[w];if(s[w]){z=q[w];B=C[w]*-1}else{z=C[w]*100+"%";B=C[w]*this.size[w]*-1}if(w===0){y.left=z;y.marginLeft=B}else{y.top=z;y.marginTop=B}}}t.css(y)};this.setParallax=function(z,C,A,D){var B=[z||r.xparallax,C||r.yparallax],w=[A||r.xorigin,D||r.yorigin],y=2,x={};while(y--){s[y]=l.px.test(B[y]);if(typeof w[y]==="string"){w[y]=w[y]===d?1:m[w[y]]||c(w[y])}if(s[y]){u[y]=parseInt(B[y]);v[y]=w[y]*(this.size[y]-u[y]);q[y]=w[y]*100+"%"}else{u[y]=B[y]===true?1:c(B[y]);v[y]=u[y]?w[y]*(1-u[y]):0}}};this.getPointer=function(){var x=t.offsetParent(),A=t.position(),w=[],z=[],y=2;while(y--){if(s[y]){w[y]=0}else{w[y]=A[y===0?"left":"top"]/(x[y===0?"outerWidth":"outerHeight"]()-this.size[y])}z[y]=(w[y]-v[y])/u[y]}return z};this.setSize=function(w,z){this.size=[w||t.outerWidth(),z||t.outerHeight()]};this.setSize(r.width,r.height);this.setParallax(r.xparallax,r.yparallax,r.xorigin,r.yorigin)}function f(x){var v=n(this),u=x.data,t=v.data(i),q=u.port,s=u.mouse,r=t.mouse,w=u.timeStamp!==x.timeStamp;if(w){u.timeStamp=x.timeStamp;q.update(a);if(q.active||!s.ontarget){s.update(q.pointer,q.threshold)}}if(r){r.update(t.freeze?t.freeze.pointer:q.pointer,q.threshold);if(r.ontarget){delete t.mouse;if(t.freeze){v.unbind(k).addClass(u.freezeClass)}}s=r}else{if(s.ontarget&&!q.active){v.unbind(k)}}t.layer.update(s.pointer)}n.fn[i]=function(t){var r=n.extend({},n.fn[i].options,t),q=arguments,s=this;if(!(r.mouseport instanceof n)){r.mouseport=n(r.mouseport)}r.port=new j(r.mouseport,r);r.mouse=new g(r);r.mouseport.bind("mouseenter",function(u){r.mouse.ontarget=false;s.each(function(w){var v=n(this);if(!v.data(i).freeze){v.bind(k,r,f)}})});return s.bind("freeze",function(z){var x=n(this),v=x.data(i),u=v.mouse||v.freeze||r.mouse,y=y=[z.x===d?u.pointer[0]:c(z.x),z.y===d?u.pointer[1]:c(z.y)],w=z.decay;v.freeze={pointer:y};v.mouse=new g(r,u.pointer);if(w!==d){v.mouse.decay=w}x.bind(k,r,f)}).bind("unfreeze",function(x){var w=n(this),u=w.data(i),v=x.decay,y;if(u.freeze){y=u.mouse?u.mouse.pointer:u.freeze.pointer;u.mouse=new g(r);u.mouse.pointer=y;if(v!==d){u.mouse.decay=v}delete u.freeze;w.removeClass(o.freezeClass).bind(k,r,f)}}).each(function(v){var x=n(this),w=q[v+1]?n.extend({},r,q[v+1]):r,u=new e(x,w);x.data(i,{layer:u,mouse:new g(w,u.getPointer())})})};n.fn[i].options=o;n(document).ready(function(){n(document).mousemove(function(q){a=[q.pageX,q.pageY]})})}(jQuery));