/*!
 * Jarallax
 * Version: 0.2.3b
 * website: http://jarallax.com
 *
 * Copyright 2012, CodeHunger
 * Dual licensed under the MIT or GPL Version 3 licenses.
 * http://jarallax.com/license.html
 * 
 * Date: 08 Aug 2012
 */
var Jarallax=function(a){this.FPS=24,this.FPS_INTERVAL=1e3/this.FPS,this.FRAME_DATA_SAMPLE=24,this.FRAME_DATA_REFRESH=12,this.fpsTop=0,this.fpsBottom=1e3,this.animations=[],this.defaultValues=[],this.progress=0,this.prev_progress=0,this.controllers=[],this.maxProgress=1,this.timer=undefined,this.allowWeakProgress=!0,this.frameRate=this.FPS,this.stepSize=0,this.jumping=!1;if(a===undefined)$.browser.iDevice?this.controllers.push(new ControllerApple(!1)):$.browser.mozilla?this.controllers.push(new ControllerScroll(!1)):this.controllers.push(new ControllerScroll(!0));else if(a!=="none")if(a.length)this.controllers=a;else if(typeof a=="object")this.controllers.push(a);else throw new Error('wrong controller data type: "'+typeof a+'". Expected "object" or "array"');for(var b in this.controllers)this.controllers[b].activate(this);this.frameChart=[];for(var c=1;c<=600;c++)this.frameChart[c]=1e3/c};Jarallax.prototype.setProgress=function(a,b){a>1?a=1:a<0?a=0:a=Math.round(a*1e3)/1e3;if(this.progress!=a){this.progress=a;if(this.allowWeakProgress||!c){this.previousTime=new Date,this.currentTime=new Date;var c=b||!1;for(var d in this.defaultValues)this.defaultValues[d].activate(this.progress);for(var e in this.animations)this.animations[e].activate(this.progress);for(var f in this.controllers)this.controllers[f].update(this.progress);this.currentTime=new Date,this.stepSize=Math.max(this.currentTime-this.previousTime,this.stepSize)}}},Jarallax.prototype.clearAnimations=function(){this.animations=[]},Jarallax.prototype.clearDefaults=function(){this.defaultValues=[]},Jarallax.prototype.clearControllers=function(){this.controllers=[]},Jarallax.prototype.jumpToProgress=function(a,b,c){return a.indexOf?a.indexOf("%")!=-1&&(a=parseFloat(a)/100):a=a/this.maxProgress,a==this.progress?!1:(a>1?a=1:a<0&&(a=0),this.smoothProperties={},this.smoothProperties.timeStep=1e3/c,this.smoothProperties.steps=b/this.smoothProperties.timeStep,this.smoothProperties.currentStep=0,this.smoothProperties.startProgress=this.progress,this.smoothProperties.diffProgress=a-this.progress,this.smoothProperties.previousValue=this.progress,this.smooth(),this.allowWeakProgress=!1,!1)},Jarallax.prototype.smooth=function(a){var b;a?b=a:b=this,b.smoothProperties.currentStep++,clearTimeout(b.timer);if(b.smoothProperties.currentStep<b.smoothProperties.steps){var c=b.smoothProperties.currentStep/b.smoothProperties.steps,d=Jarallax.EASING.easeOut(c,b.smoothProperties.startProgress,b.smoothProperties.diffProgress,1,5);b.jumping_allowed=!0,b.setProgress(d),b.jumping_allowed=!1,b.timer=window.setTimeout(function(){b.smooth(b)},b.smoothProperties.timeStep),b.smoothProperties.previousValue=d,b.allowWeakProgress=!1}else b.jumping_allowed=!0,b.setProgress(b.smoothProperties.startProgress+b.smoothProperties.diffProgress),b.jumping_allowed=!1,b.clearSmooth(b)},Jarallax.prototype.clearSmooth=function(a){a.allowWeakProgress=!0,clearTimeout(a.timer),delete a.smoothProperties},Jarallax.prototype.setDefault=function(a,b){if(!a)throw new Error("no selector defined.");if(JarallaxTools.isValues(b)){var c=new JarallaxObject(a,b);c.activate(),this.defaultValues.push(c)}},Jarallax.prototype.addStatic=function(a,b){if(!a)throw new Error("no selector defined.");if(JarallaxTools.isValues(b)){var c=new JarallaxStatic(a,b[0],b[1]);this.defaultValues.push(c)}},Jarallax.prototype.addCounter=function(a){this.animations.push(new JarallaxCounter(this,a))},Jarallax.prototype.addController=function(a,b){this.controllers.push(a),b&&a.activate(this)},Jarallax.prototype.addAnimation=function(a,b,c,d){c?c.substring?c=[c]:c=c||[JarallaxTools.Platform.Any]:c=["any"];if(JarallaxTools.PlatformAllowed(c,d)){var e;if(!a)throw new Error("no selector defined.");var f=[];if(JarallaxTools.isValues(b))if(b.length)for(var g=0;g<b.length-1;g++){if(!b[g]||!b[g+1])throw new Error("bad animation data.");if(b[g].progress&&b[g+1].progress)b[g+1].progress.indexOf("%")==-1&&this.maxProgress<b[g+1].progress&&(this.maxProgress=b[g+1].progress),e=new JarallaxAnimation(a,b[g],b[g+1],this),this.animations.push(e),f.push(e);else throw new Error("no animation boundry found.")}else{b.progress||(b.progress="100%");var h={};for(var i in b)h[i]=$(a).css(i);h.progress="0%",e=new JarallaxAnimation(a,h,b,this),this.animations.push(e),f.push(e)}return f}return!1},Jarallax.prototype.cloneAnimation=function(a,b,c){if(!a)throw new Error("no selector defined.");var d=[],e=[];for(var f=0;f<c.length+1;f++)b instanceof Array?e.push(b[f]):e.push(b);for(f=0;f<c.length;f++){var g=c[f],h=JarallaxTools.clone(g.startValues),i=JarallaxTools.clone(g.endValues),j=e[f],k=e[f+1];for(var l in h)j[l]&&(h[l]=JarallaxTools.calculateNewValue(j[l],h[l]));for(var m in i)k[m]&&(i[m]=JarallaxTools.calculateNewValue(k[m],i[m]));d.push(this.addAnimation(a,[h,i])[0])}return d},Jarallax.EASING={linear:function(a,b,c,d,e){return a/d*c+b},easeOut:function(a,b,c,d,e){return e===undefined&&(e=2),(Math.pow((d-a)/d,e)*-1+1)*c+b},easeIn:function(a,b,c,d,e){return e===undefined&&(e=2),Math.pow(a/d,e)*c+b},easeInOut:function(a,b,c,d,e){return e===undefined&&(e=2),c/=2,a*=2,a<d?Math.pow(a/d,e)*c+b:(a=a-d,(Math.pow((d-a)/d,e)*-1+1)*c+b+c)}},Jarallax.EASING.none=Jarallax.EASING.linear,JarallaxTools={},JarallaxTools.hasNumbers=function(a){var b=new RegExp("\\d");return b.test(a)},JarallaxTools.isValues=function(a){if(!a)throw new Error("no values set.");if(typeof a!="object")throw new Error('wrong data type values. expected: "object", got: "'+typeof a+'"');if(a.size===0)throw new Error("Got an empty values object");return!0},JarallaxTools.PlatformAllowed=function(a,b,c){b=b||!1,c=c||!1;for(var d=0;d<a.length;d++){if(a[d]=="any")return!c;if(jQuery.browser[a[d]]){if(!b)return!c}else if(b)return c}return c?!b:b},JarallaxTools.calculateNewValue=function(a,b){var c,d=JarallaxTools.getUnits(b);return a.indexOf("+")===0?c=String(parseFloat(b)+parseFloat(a)+d):a.indexOf("-")===0?c=String(parseFloat(b)+parseFloat(a)+d):a.indexOf("*")===0?c=String(parseFloat(b)*parseFloat(a.substr(1))+d):a.indexOf("/")===0?c=String(parseFloat(b)/parseFloat(a.substr(1))+d):c=a,b.indexOf&&b.indexOf("%")>0?c+"%":c},JarallaxTools.getUnits=function(a){return a.replace(/\d+/g,"")},JarallaxTools.clone=function(a){var b={};for(var c in a)b[c]=a[c];return b},Position=function(a,b){this.x=a,this.y=b},Position.prototype.add=function(a){return new Position(this.x+a.x,this.y+a.y)},Position.prototype.subract=function(a){return new Position(this.x-a.x,this.y-a.y)},JarallaxTools.Platforms=["webkit","opera","msie","mozilla","android","blackBerry","webOs","windowsPhone","iDevice","iPad","iPhone","iPod","msie","mobile","nonMobile"],jQuery.browser.android=/android/i.test(navigator.userAgent.toLowerCase()),jQuery.browser.blackBerry=/blackberry/i.test(navigator.userAgent.toLowerCase()),jQuery.browser.webOs=/webos/i.test(navigator.userAgent.toLowerCase()),jQuery.browser.windowsPhone=/windows phone/i.test(navigator.userAgent.toLowerCase()),jQuery.browser.iDevice=/ipad|iphone|ipod/i.test(navigator.userAgent.toLowerCase()),jQuery.browser.iPad=/ipad/i.test(navigator.userAgent.toLowerCase()),jQuery.browser.iPhone=/iphone/i.test(navigator.userAgent.toLowerCase()),jQuery.browser.iPod=/ipod/i.test(navigator.userAgent.toLowerCase()),jQuery.browser.mobile=jQuery.browser.android||jQuery.browser.blackBerry||jQuery.browser.webOs||jQuery.browser.windowsPhone||jQuery.browser.iDevice,jQuery.browser.nonMobile=!jQuery.browser.mobile,jQuery.platform={},jQuery.platform.windows=navigator.appVersion.indexOf("Win")!=-1,jQuery.platform.macOs=navigator.appVersion.indexOf("Mac")!=-1,jQuery.platform.unix=navigator.appVersion.indexOf("X11")!=-1,jQuery.platform.linux=navigator.appVersion.indexOf("Linux")!=-1,jQuery.platform.unknown=!(jQuery.platform.windows||jQuery.platform.macOs||jQuery.platform.unix||jQuery.platform.linux),JarallaxController=function(){this.isActive=!1,this.bindings=[]},JarallaxController.prototype.activate=function(a){this.isActive=!0;if(!this.jarallax||this.jarallax!==a)this.jarallax=a},JarallaxController.prototype.deactivate=function(a){this.isActive=!1},JarallaxController.prototype.update=function(a){},JarallaxCounter=function(a,b){if(!b)throw new Error("No properties defined.");if(!b.selector)throw new Error("No selector defined. properties.selector.");this.jarallax=a,this.selector=b.selector,this.startNumber=b.startNumber||0,this.endNumber=b.endNumber||100,this.startProgress=b.startProgress||"0%",this.endProgress=b.endProgress||"100%",this.decimals=b.decimals||0,this.stepSize=b.stepSize,this.decimals===0&&this.stepSize<1&&(tmp=this.stepSize.toString().split("."),this.decimals=tmp[1].length)},JarallaxCounter.prototype.activate=function(){var a=this.endNumber-this.startNumber,b=a*this.jarallax.progress+this.startNumber;this.startProgress.indexOf("%")>=0?start=parseInt(this.startProgress,10)/100:JarallaxTools.hasNumbers(this.startProgress)&&(start=parseInt(this.startProgress,10)/this.jarallax.maxProgress),this.endProgress.indexOf("%")>=0?end=parseInt(this.endProgress,10)/100:JarallaxTools.hasNumbers(this.endProgress)&&(end=parseInt(this.endProgress,10)/this.jarallax.maxProgress);if(this.jarallax.progress<start)$(this.selector).html(this.startNumber);else if(this.jarallax.progress>end)$(this.selector).html(this.endNumber);else{var c=end-start,d=this.jarallax.progress-start,e=this.endNumber-this.startNumber,f=Jarallax.EASING.none(d,this.startNumber,e,c);this.stepSize&&(f=Math.round(f/this.stepSize)*this.stepSize),this.decimals>0&&(f=f.toFixed(this.decimals)),$(this.selector).html(f)}},JarallaxObject=function(a,b){this.selector=a,this.values=b},JarallaxObject.prototype.activate=function(a){for(var b in this.values)$(this.selector).css(b,this.values[b])},JarallaxAnimation=function(a,b,c,d){this.progress=-1,this.selector=a,this.startValues=b,this.endValues=c,this.jarallax=d},JarallaxAnimation.prototype.activate=function(a){if(this.progress!=a){var b,c,d;this.startValues.style===undefined?d={easing:"linear"}:d=this.startValues.style,this.startValues.progress.indexOf("%")>=0?b=parseInt(this.startValues.progress,10)/100:JarallaxTools.hasNumbers(this.startValues.progress)&&(b=parseInt(this.startValues.progress,10)/this.jarallax.maxProgress),this.endValues.progress.indexOf("%")>=0?c=parseInt(this.endValues.progress,10)/100:JarallaxTools.hasNumbers(this.endValues.progress)&&(c=parseInt(this.endValues.progress,10)/this.jarallax.maxProgress),this.startValues.event&&this.dispatchEvent(this.progress,a,b,c);if(a>=b&&a<=c)for(var e in this.startValues)if(e!=="progress"&&e!=="style"&&e!=="event")if(undefined!==this.endValues[e]&&e!=="display"&&e!=="backgroundImage"){var f=JarallaxTools.getUnits(this.startValues[e]+"");f=f.replace("-","");var g=parseFloat(this.startValues[e]),h=parseFloat(this.endValues[e]),i=c-b,j=a-b,k=h-g,l=Jarallax.EASING[d.easing](j,g,k,i,d.power);f=="px"&&(l=parseInt(l,10)),f!=="."&&(l+=f),$(this.selector).css(e,l)}else $(this.selector).css(e,this.startValues[e]);this.progress=a}},JarallaxAnimation.prototype.dispatchEvent=function(a,b,c,d){var e=this.startValues.event,f={};f.animation=this,f.selector=this.selector,b>=c&&b<=d?(e.start&&a<c&&(f.type="start",e.start(f)),e.start&&a>d&&(f.type="rewind",e.start(f)),e.animating&&(f.type="animating",e.animating(f)),e.forward&&a<b&&(f.type="forward",e.forward(f)),e.reverse&&a>b&&(f.type="reverse",e.reverse(f))):(e.complete&&a<d&&b>d&&(f.type="complete",e.complete(f)),e.rewinded&&a>c&&b<c&&(f.type="rewind",e.rewinded(f)))},ControllerApple=function(a){a===undefined?this.scrollPage=!0:this.scrollPage=a,this.target=$("body"),this.scrollPostion=new Position(0,0)},ControllerApple.prototype=new JarallaxController,ControllerApple.prototype.activate=function(a){JarallaxController.prototype.activate.call(this,a),this.scrollSpace=$("body").height()-$(window).height(),this.target.bind("touchmove",{scope:this},this.onMove),this.target.bind("touchstart",{scope:this},this.onTouch)},ControllerApple.prototype.deactivate=function(a){JarallaxController.prototype.deactivate.call(this,a),this.target.unbind("touchmove"),this.target.unbind("touchstart")},ControllerApple.prototype.onTouch=function(a){var b=a.data.scope,c=a.originalEvent.touches.item(0);b.startPosition=new Position(c.clientX,c.clientY),a.preventDefault()},ControllerApple.prototype.onMove=function(a){var b=a.data.scope,c=a.originalEvent.touches.item(0),d=new Position(c.clientX,c.clientY),e=d.subract(b.startPosition);b.startPosition=d,b.scrollPostion=e.add(b.scrollPostion),b.scrollPostion.y=Math.max(Math.min(b.scrollPostion.y,0),-b.scrollSpace),b.jarallax.setProgress(-b.scrollPostion.y/b.scrollSpace,!1),$("body").scrollTop(b.scrollSpace*b.jarallax.progress),b.scrollPage||a.preventDefault()},ControllerApple.prototype.update=function(a){this.position.y=Math.round(a*this.scrollSpace)},ControllerMobile=function(a,b){this.disableDefault=a||!1,this.y=0,this.previousY=undefined,this.height=b},ControllerMobile.prototype=new JarallaxController,ControllerMobile.prototype.activate=function(a){JarallaxController.prototype.activate.call(this,a),this.height||(this.height=this.height=parseInt($("body").css("height"),10),this.height==$(window).height&&(this.height=parseInt($("#wrapper").css("height"),10))),$("body").bind("touchmove",{scope:this},this.onTouchMove),$("body").bind("touchend",{scope:this},this.onTouchEnd)},ControllerMobile.prototype.onTouchEnd=function(a){this.previousY=undefined},ControllerMobile.prototype.onTouchMove=function(a,b){if(this.isActive){this.disableDefault&&a.preventDefault();var c=a.data.scope,d=b?a:a.originalEvent.touches.item(0);if(c.previousY===undefined)c.previousY=d.clientY;else{c.y+=d.clientY-c.previousY,c.y=c.y<c.height?c.y:c.height,c.y=c.y>0?c.y:0,c.previousY=d.clientY;var e=c.y/c.height;c.jarallax.setProgress(c.y/c.height)}}},ControllerMobile.prototype.deactivate=function(a){JarallaxController.prototype.deactivate.call(this,a),$("body").unbind("touchmove")},ControllerMobile.prototype.update=function(a){},ControllerScroll=function(a,b){this.target=$(window),$(window).scrollTop(0),this.height=parseInt($("body").css("height"),10),this.scrollSpace=b||this.height-this.target.height(),this.scrollSpace<10&&(this.height=parseInt($("#wrapper").css("height"),10),this.scrollSpace=this.height-this.target.height()),this.smoothing=a||!1,this.targetProgress=0},ControllerScroll.prototype=new JarallaxController,ControllerScroll.prototype.activate=function(a){JarallaxController.prototype.activate.call(this,a),this.target.bind("scroll",{scope:this},this.onScroll)},ControllerScroll.prototype.deactivate=function(a){JarallaxController.prototype.deactivate.call(this,a),this.target.unbind("scroll")},ControllerScroll.prototype.onScroll=function(a){var b=a.data.scope;b.jarallax.jumping&&(b.jarallax.jumping_allowed||b.jarallax.clearSmooth(b.jarallax));if(b.isActive){var c=a.data.y||b.target.scrollTop(),d=c/b.scrollSpace;b.smoothing?(b.targetProgress=d,b.smooth()):b.jarallax.setProgress(d,!0)}},ControllerScroll.prototype.smooth=function(a){var b;a?b=a:b=this;var c=b.jarallax.progress,d=b.targetProgress-c;clearTimeout(b.timer);if(d>1e-4||d<-0.0001){var e=c+d/5;b.timer=window.setTimeout(function(){b.smooth(b)},b.jarallax.FPS_INTERVAL),b.jarallax.setProgress(e,!0)}else b.jarallax.setProgress(b.targetProgress,!0)},ControllerScroll.prototype.update=function(a){var b=a*this.scrollSpace;this.jarallax.allowWeakProgress||$(window).scrollTop(b)},ControllerDrag=function(a,b,c){this.object=$(a),this.start=b,this.end=c,this.container="",this.width=0,this.startX=0,this.startY=0},ControllerDrag.prototype=new JarallaxController,ControllerDrag.prototype.activate=function(a){JarallaxController.prototype.activate.call(this,a),this.container="#scrollbar",this.object.draggable({containment:this.container,axis:"x"}),this.object.bind("drag",{scope:this},this.onDrag),this.container=$(this.container),this.width=$(this.container).innerWidth()-this.object.outerWidth()},ControllerDrag.prototype.onDrag=function(a){var b=a.data.scope;if(b.isActive){var c=parseInt($(this).css("left"),10),d=c/a.data.scope.width;a.data.scope.jarallax.setProgress(d)}},ControllerDrag.prototype.deactivate=function(a){JarallaxController.prototype.deactivate.call(this,a),this.object.unbind("drag"),this.object.draggable("destroy")},ControllerDrag.prototype.update=function(a){this.object.css("left",a*this.width)},ControllerKeyboard=function(a,b,c){this.repetitiveInput=c,this.preventDefault=b||!1,this.keys=a||{38:-0.01,40:.01},this.keysState={}},ControllerKeyboard.prototype=new JarallaxController,ControllerKeyboard.prototype.activate=function(a){JarallaxController.prototype.activate.call(this,a),$(document.documentElement).keydown({scope:this},this.keyDown),$(document.documentElement).keyup({scope:this},this.keyUp);for(var b in this.keys)this.keysState[b]=!1},ControllerKeyboard.prototype.deactivate=function(a){JarallaxController.prototype.deactivate.call(this,a)},ControllerKeyboard.prototype.keyDown=function(a){var b=a.data.scope;if(b.isActive)for(var c in b.keys)c==a.keyCode&&((b.keysState[c]!==!0||b.repetitiveInput)&&b.jarallax.setProgress(b.jarallax.progress+b.keys[c]),b.keysState[c]=!0,b.preventDefault&&a.preventDefault())},ControllerKeyboard.prototype.keyUp=function(a){if(this.isActive){var b=a.data.scope;for(var c in b.keys)c==a.keyCode&&(b.keysState[c]=!1)}},ControllerKeyboard.prototype.update=function(a){},ControllerTime=function(a,b,c){this.interval=b,this.speed=a,this.playForward=!0,this.type=c||ControllerTime.TYPES.NORMAL},ControllerTime.prototype=new JarallaxController,ControllerTime.prototype.activate=function(a){JarallaxController.prototype.activate.call(this,a),this.progress=0,this.timer=setInterval(this.onInterval.bind(this,{scope:this}),this.interval)},ControllerTime.prototype.deactivate=function(a){JarallaxController.prototype.deactivate.call(this,a),clearInterval(this.timer)},ControllerTime.prototype.onInterval=function(a){var b=a.scope;if(this.isActive){this.playForward?this.progress+=this.speed:this.progress-=this.speed;if(this.progress>=1)switch(this.type){case ControllerTime.TYPES.NORMAL:this.progress=1,this.deactivate(this.jarallax);break;case ControllerTime.TYPES.LOOP:this.progress=0;break;case ControllerTime.TYPES.BOUNCE:this.progress=1-this.speed,this.playForward=!1}else this.progress<=0&&(this.progress=0+this.speed,this.playForward=!0);this.jarallax.setProgress(this.progress)}},ControllerTime.TYPES={NORMAL:0,LOOP:1,BOUNCE:2},ControllerTime.prototype.update=function(a){this.progress=a},ControllerMousewheel=function(a,b){this.sensitivity=-a,this.preventDefault=b||!1},ControllerMousewheel.prototype=new JarallaxController,ControllerMousewheel.prototype.activate=function(a){JarallaxController.prototype.activate.call(this,a),$("body").bind("mousewheel",{scope:this},this.onScroll)},ControllerMousewheel.prototype.deactivate=function(a){$("body").unbind("mousewheel"),JarallaxController.prototype.deactivate(this,a)},ControllerMousewheel.prototype.onScroll=function(a,b){var c=a.data.scope;c.isActive&&(c.jarallax.setProgress(c.jarallax.progress+c.sensitivity*b),c.preventDefault&&a.preventDefault())},ControllerMousewheel.prototype.update=function(a){};