/*
 * Overscroll v1.3.5
 *  A jQuery Plugin that emulates the iPhone scrolling experience in a browser.
 *  http://azoffdesign.com/overscroll
 *
 * Intended for use with the latest jQuery
 *  http://code.jquery.com/jquery-latest.min.js
 *
 * Copyright 2010, Jonathan Azoff
 * Dual licensed under the MIT or GPL Version 2 licenses.
 *  http://jquery.org/license
 *
 * Date: Thursday, August 26th 2010
 */
"use strict";(function(b,a,c,d){d=c.fn.overscroll=function(e){return this.each(function(){d.init(c(this),e)})};c.extend(d,{events:{wheel:"mousewheel DOMMouseScroll",start:"select mousedown touchstart",drag:"mousemove touchmove",scroll:"scroll",end:"mouseup mouseleave touchend",ignored:"dragstart drag"},div:"<div/>",noop:function(){return false},constants:{scrollDuration:800,timeout:400,captureThreshold:3,wheelDelta:20,scrollDelta:5.9,thumbThickness:8,thumbOpacity:0.7,boundingBox:1000000},init:function(g,e,f){f={sizing:d.getSizing(g)};e=c.extend({openedCursor:"http://github.com/downloads/azoff/Overscroll/opened.cur",closedCursor:"http://github.com/downloads/azoff/Overscroll/closed.cur",showThumbs:true,wheelDirection:"vertical",wheelDelta:d.constants.wheelDelta,scrollDelta:d.constants.scrollDelta,direction:"multi",onDriftEnd:c.noop},(e||{}));e.scrollDelta=a.abs(e.scrollDelta);e.wheelDelta=a.abs(e.wheelDelta);e.cache={openedCursor:new Image(),closedCursor:new Image()};e.cache.openedCursor.src=e.openedCursor;e.cache.closedCursor.src=e.closedCursor;e.openedCss={cursor:"url('"+e.openedCursor+"'),default"};e.closedCss={cursor:"url('"+e.closedCursor+"'),default"};g.css("overflow","hidden").css(e.openedCss).bind(d.events.wheel,f,d.wheel).bind(d.events.start,f,d.start).bind(d.events.end,f,d.stop).bind(d.events.ignored,d.noop);if(e.showThumbs){f.thumbs={};if(f.sizing.container.scrollWidth>0&&e.direction!=="vertical"){f.thumbs.horizontal=c(d.div).css(d.getThumbCss(f.sizing.thumbs.horizontal)).fadeTo(0,0);g.prepend(f.thumbs.horizontal)}if(f.sizing.container.scrollHeight>0&&e.direction!=="horizontal"){f.thumbs.vertical=c(d.div).css(d.getThumbCss(f.sizing.thumbs.vertical)).fadeTo(0,0);g.prepend(f.thumbs.vertical)}f.sizing.relative=f.thumbs.vertical||f.thumbs.horizontal;if(f.sizing.relative){f.sizing.relative.oldOffset=f.sizing.relative.offset();g.scrollTop(d.constants.boundingBox).scrollLeft(d.constants.boundingBox);f.sizing.relative.remove().prependTo(g);f.sizing.relative.newOffset=f.sizing.relative.offset();f.sizing.relative=f.sizing.relative.oldOffset.left!=f.sizing.relative.newOffset.left||f.sizing.relative.oldOffset.top!=f.sizing.relative.newOffset.top;g.scrollTop(0).scrollLeft(0);g.bind(d.events.scroll,f,d.scroll)}}f.target=g;f.options=e},toggleDragMode:function(f,e){if(e){f.target.css(f.options.closedCss)}else{f.target.css(f.options.openedCss)}if(f.thumbs){if(e){if(f.thumbs.vertical){f.thumbs.vertical.stop(true,true).fadeTo("fast",d.constants.thumbOpacity)}if(f.thumbs.horizontal){f.thumbs.horizontal.stop(true,true).fadeTo("fast",d.constants.thumbOpacity)}}else{if(f.thumbs.vertical){f.thumbs.vertical.fadeTo("fast",0)}if(f.thumbs.horizontal){f.thumbs.horizontal.fadeTo("fast",0)}}}},setPosition:function(g,e,f){e.x=g.pageX;e.y=g.pageY;e.index=f;return e},wheel:function(e,f){if(e.wheelDelta){f=e.wheelDelta/(b.opera?-120:120)}if(e.detail){f=-e.detail/3}if(!e.data.wheelCapture){e.data.wheelCapture={timeout:null};d.toggleDragMode(e.data,true);e.data.target.stop(true,true).data("dragging",true)}f*=e.data.options.wheelDelta;if(e.data.options.wheelDirection==="horizontal"){this.scrollLeft-=f}else{this.scrollTop-=f}if(e.data.wheelCapture.timeout){clearTimeout(e.data.wheelCapture.timeout)}e.data.wheelCapture.timeout=setTimeout(function(g){e.data.wheelCapture=undefined;d.toggleDragMode(e.data,false);e.data.target.data("dragging",false);e.data.options.onDriftEnd.call(e.data.target,e.data)},d.constants.timeout);return false},scroll:function(h,f,e,j,i,k,g){f=h.data.thumbs;e=h.data.sizing;j=this.scrollLeft;i=this.scrollTop;if(f.horizontal){k=j*e.container.width/e.container.scrollWidth;g=e.thumbs.horizontal.top;if(e.relative){k+=j;g+=i}f.horizontal.css("margin",g+"px 0 0 "+k+"px")}if(f.vertical){k=e.thumbs.vertical.left;g=i*e.container.height/e.container.scrollHeight;if(e.relative){k+=j;g+=i}f.vertical.css("margin",g+"px 0 0 "+k+"px")}},start:function(e){e.data.target.bind(d.events.drag,e.data,d.drag).stop(true,true).data("dragging",false);d.toggleDragMode(e.data,true);e.data.position=d.setPosition(e,{});e.data.capture=d.setPosition(e,{},2);return false},drag:function(f,i,e,h,g){if(f.data.options.direction!=="vertical"){this.scrollLeft-=(f.pageX-f.data.position.x)}if(f.data.options.direction!=="horizontal"){this.scrollTop-=(f.pageY-f.data.position.y)}d.setPosition(f,f.data.position);if(--f.data.capture.index<=0){f.data.target.data("dragging",true);d.setPosition(f,f.data.capture,d.constants.captureThreshold)}return true},stop:function(g,f,e,h){if(g.data.position){g.data.target.unbind(d.events.drag,d.drag);if(g.data.target.data("dragging")){f=g.data.options.scrollDelta*(g.pageX-g.data.capture.x);e=g.data.options.scrollDelta*(g.pageY-g.data.capture.y);h={};if(g.data.options.direction!=="vertical"){h.scrollLeft=this.scrollLeft-f}if(g.data.options.direction!=="horizontal"){h.scrollTop=this.scrollTop-e}g.data.target.animate(h,{duration:d.constants.scrollDuration,easing:"cubicEaseOut",complete:function(){g.data.target.data("dragging",false);g.data.options.onDriftEnd.call(g.data.target,g.data);d.toggleDragMode(g.data,false)}})}else{d.toggleDragMode(g.data,false)}g.data.capture=g.data.position=undefined}return !g.data.target.data("dragging")},getSizing:function(f,e){e={};e.container={width:f.width(),height:f.height()};f.scrollLeft(d.constants.boundingBox).scrollTop(d.constants.boundingBox);e.container.scrollWidth=f.scrollLeft();e.container.scrollHeight=f.scrollTop();f.scrollTop(0).scrollLeft(0);e.thumbs={horizontal:{width:e.container.width*e.container.width/e.container.scrollWidth,height:d.constants.thumbThickness,corner:d.constants.thumbThickness/2,left:0,top:e.container.height-d.constants.thumbThickness},vertical:{width:d.constants.thumbThickness,height:e.container.height*e.container.height/e.container.scrollHeight,corner:d.constants.thumbThickness/2,left:e.container.width-d.constants.thumbThickness,top:0}};e.container.width-=e.thumbs.horizontal.width;e.container.height-=e.thumbs.vertical.height;return e},getThumbCss:function(e){return{position:"absolute","background-color":"black",width:e.width+"px",height:e.height+"px",margin:e.top+"px 0 0 "+e.left+"px","-moz-border-radius":e.corner+"px","-webkit-border-radius":e.corner+"px","border-radius":e.corner+"px"}}});c.extend(c.easing,{cubicEaseOut:function(g,i,e,f){var h=e+f;return h*((g=g/1-1)*g*g+1)+e}})})(window,Math,jQuery);
