define(["angular"],function(a){a.module("duScroll",["duScroll.scrollspy","duScroll.smoothScroll","duScroll.scrollContainer","duScroll.spyContext","duScroll.scrollHelpers"]).value("duScrollDuration",350).value("duScrollSpyWait",100).value("duScrollGreedy",!1).value("duScrollOffset",0).value("duScrollEasing",function(e){"use strict";return e<.5?Math.pow(2*e,2)/2:1-Math.pow(2*(1-e),2)/2}).value("duScrollCancelOnEvents","scroll mousedown mousewheel touchmove keydown").value("duScrollBottomSpy",!1).value("duScrollActiveClass","active"),a.module("duScroll.scrollHelpers",["duScroll.requestAnimation"]).run(["$window","$q","cancelAnimation","requestAnimation","duScrollEasing","duScrollDuration","duScrollOffset","duScrollCancelOnEvents",function(i,p,m,S,h,r,c,v){"use strict";function u(e){return"undefined"!=typeof HTMLDocument&&e instanceof HTMLDocument||e.nodeType&&e.nodeType===e.DOCUMENT_NODE}function s(e){return"undefined"!=typeof HTMLElement&&e instanceof HTMLElement||e.nodeType&&e.nodeType===e.ELEMENT_NODE}function d(e){return s(e)||u(e)?e:e[0]}var y,g,e={};e.duScrollTo=function(e,t,o,n){var r;if(a.isElement(e)?r=this.duScrollToElement:a.isDefined(o)&&(r=this.duScrollToAnimated),r)return r.apply(this,arguments);var l=d(this);if(u(l))return i.scrollTo(e,t);l.scrollLeft=e,l.scrollTop=t},e.duScrollToAnimated=function(e,t,o,n){o&&!n&&(n=h);var r=this.duScrollLeft(),l=this.duScrollTop(),i=Math.round(e-r),c=Math.round(t-l),u=null,s=0,d=this,a=function(e){(!e||s&&0<e.which)&&(v&&d.unbind(v,a),m(y),g.reject(),y=null)};if(y&&a(),g=p.defer(),0===o||!i&&!c)return 0===o&&d.duScrollTo(e,t),g.resolve(),g.promise;var f=function(e){null===u&&(u=e);var t=o<=(s=e-u)?1:n(s/o);d.scrollTo(r+Math.ceil(i*t),l+Math.ceil(c*t)),t<1?y=S(f):(v&&d.unbind(v,a),y=null,g.resolve())};return d.duScrollTo(r,l),v&&d.bind(v,a),y=S(f),g.promise},e.duScrollToElement=function(e,t,o,n){var r=d(this);a.isNumber(t)&&!isNaN(t)||(t=c);var l=this.duScrollTop()+d(e).getBoundingClientRect().top-t;return s(r)&&(l-=r.getBoundingClientRect().top),this.duScrollTo(0,l,o,n)},e.duScrollLeft=function(e,t,o){if(a.isNumber(e))return this.duScrollTo(e,this.duScrollTop(),t,o);var n=d(this);return u(n)?i.scrollX||document.documentElement.scrollLeft||document.body.scrollLeft:n.scrollLeft},e.duScrollTop=function(e,t,o){if(a.isNumber(e))return this.duScrollTo(this.duScrollLeft(),e,t,o);var n=d(this);return u(n)?i.scrollY||document.documentElement.scrollTop||document.body.scrollTop:n.scrollTop},e.duScrollToElementAnimated=function(e,t,o,n){return this.duScrollToElement(e,t,o||r,n)},e.duScrollTopAnimated=function(e,t,o){return this.duScrollTop(e,t||r,o)},e.duScrollLeftAnimated=function(e,t,o){return this.duScrollLeft(e,t||r,o)},a.forEach(e,function(e,t){a.element.prototype[t]=e;var o=t.replace(/^duScroll/,"scroll");a.isUndefined(a.element.prototype[o])&&(a.element.prototype[o]=e)})}]),a.module("duScroll.polyfill",[]).factory("polyfill",["$window",function(l){"use strict";var i=["webkit","moz","o","ms"];return function(e,t){if(l[e])return l[e];for(var o,n=e.substr(0,1).toUpperCase()+e.substr(1),r=0;r<i.length;r++)if(l[o=i[r]+n])return l[o];return t}}]),a.module("duScroll.requestAnimation",["duScroll.polyfill"]).factory("requestAnimation",["polyfill","$timeout",function(e,l){"use strict";var i=0;return e("requestAnimationFrame",function(e,t){var o=(new Date).getTime(),n=Math.max(0,16-(o-i)),r=l(function(){e(o+n)},n);return i=o+n,r})}]).factory("cancelAnimation",["polyfill","$timeout",function(e,t){"use strict";return e("cancelAnimationFrame",function(e){t.cancel(e)})}]),a.module("duScroll.spyAPI",["duScroll.scrollContainerAPI"]).factory("spyAPI",["$rootScope","$timeout","$window","$document","scrollContainerAPI","duScrollGreedy","duScrollSpyWait","duScrollBottomSpy","duScrollActiveClass",function(f,n,p,m,o,S,r,h,v){"use strict";function e(e){var t=e.$id,o={spies:[]};return o.handler=function(d){function e(){a=!1;var e,t=d.container[0],o=0;e="undefined"!=typeof HTMLElement&&t instanceof HTMLElement||t.nodeType&&t.nodeType===t.ELEMENT_NODE?(o=t.getBoundingClientRect().top,Math.round(t.scrollTop+t.clientHeight)>=t.scrollHeight):Math.round(p.pageYOffset+p.innerHeight)>=m[0].body.scrollHeight;var n,r,l,i,c,u,s=h&&e?"bottom":"top";for(i=d.spies,r=d.currentlyActive,l=void 0,n=0;n<i.length;n++)(u=(c=i[n]).getTargetPosition())&&(h&&e||u.top+c.offset-o<20&&(S||-1*u.top+o)<u.height)&&(!l||l[s]<u[s])&&((l={spy:c})[s]=u[s]);r===(l=l&&l.spy)||S&&!l||(r&&(r.$element.removeClass(v),f.$broadcast("duScrollspy:becameInactive",r.$element)),l&&(l.$element.addClass(v),f.$broadcast("duScrollspy:becameActive",l.$element)),d.currentlyActive=l)}var t=!1,a=!1;return r?function(){t?a=!0:(e(),t=n(function(){t=!1,a&&e()},r,!1))}:e}(o),i[t]=o,e.$on("$destroy",function(){c(e)}),t}function l(e){var t,o,n=e.$scope;if(n)return u(n);for(o in i)if(-1!==(t=i[o]).spies.indexOf(e))return t}var i={},c=function(e){var t=e.$id,o=i[t],n=o.container;n&&n.off("scroll",o.handler),delete i[t]},t=e(f),u=function(e){return i[e.$id]?i[e.$id]:e.$parent?u(e.$parent):i[t]};return{addSpy:function(e){var t=l(e);t&&(t.spies.push(e),t.container&&function(e){for(;e.parentNode;)if((e=e.parentNode)===document)return!0;return!1}(t.container)||(t.container&&t.container.off("scroll",t.handler),t.container=o.getContainer(e.$scope),t.container.on("scroll",t.handler).triggerHandler("scroll")))},removeSpy:function(e){var t=l(e);if(t){e===t.currentlyActive&&(t.currentlyActive=null);var o=t.spies.indexOf(e);-1!==o&&t.spies.splice(o,1),e.$element=null}},createContext:e,destroyContext:c,getContextForScope:u}}]),a.module("duScroll.scrollContainerAPI",[]).factory("scrollContainerAPI",["$document",function(o){"use strict";var n={},r=function(e){return n[e.$id]?e.$id:e.$parent?r(e.$parent):void 0};return{getContainerId:r,getContainer:function(e){var t=r(e);return t?n[t]:o},setContainer:function(e,t){var o=e.$id;return n[o]=t,o},removeContainer:function(e){var t=r(e);t&&delete n[t]}}}]),a.module("duScroll.smoothScroll",["duScroll.scrollHelpers","duScroll.scrollContainerAPI"]).directive("duSmoothScroll",["duScrollDuration","duScrollOffset","scrollContainerAPI",function(c,u,s){"use strict";return{link:function(l,e,i){e.on("click",function(e){if(i.href&&-1!==i.href.indexOf("#")||""!==i.duSmoothScroll){var t=i.href?i.href.replace(/.*(?=#[^\s]+$)/,"").substring(1):i.duSmoothScroll,o=document.getElementById(t)||document.getElementsByName(t)[0];if(o&&o.getBoundingClientRect){e.stopPropagation&&e.stopPropagation(),e.preventDefault&&e.preventDefault();var n=i.offset?parseInt(i.offset,10):u,r=i.duration?parseInt(i.duration,10):c;s.getContainer(l).duScrollToElement(a.element(o),isNaN(n)?0:n,isNaN(r)?0:r)}}})}}}]),a.module("duScroll.spyContext",["duScroll.spyAPI"]).directive("duSpyContext",["spyAPI",function(r){"use strict";return{restrict:"A",scope:!0,compile:function(e,t,o){return{pre:function(e,t,o,n){r.createContext(e)}}}}}]),a.module("duScroll.scrollContainer",["duScroll.scrollContainerAPI"]).directive("duScrollContainer",["scrollContainerAPI",function(r){"use strict";return{restrict:"A",scope:!0,compile:function(e,t,o){return{pre:function(t,o,e,n){e.$observe("duScrollContainer",function(e){a.isString(e)&&(e=document.getElementById(e)),e=a.isElement(e)?a.element(e):o,r.setContainer(t,e),t.$on("$destroy",function(){r.removeContainer(t)})})}}}}}]),a.module("duScroll.scrollspy",["duScroll.spyAPI"]).directive("duScrollspy",["spyAPI","duScrollOffset","$timeout","$rootScope",function(i,c,t,u){"use strict";function s(e,t,o,n){a.isElement(e)?this.target=e:a.isString(e)&&(this.targetId=e),this.$scope=t,this.$element=o,this.offset=n}return s.prototype.getTargetElement=function(){return!this.target&&this.targetId&&(this.target=document.getElementById(this.targetId)||document.getElementsByName(this.targetId)[0]),this.target},s.prototype.getTargetPosition=function(){var e=this.getTargetElement();if(e)return e.getBoundingClientRect()},s.prototype.flushTargetCache=function(){this.targetId&&(this.target=void 0)},{link:function(o,n,r){var l,e=r.ngHref||r.href;e&&-1!==e.indexOf("#")?l=e.replace(/.*(?=#[^\s]+$)/,"").substring(1):r.duScrollspy?l=r.duScrollspy:r.duSmoothScroll&&(l=r.duSmoothScroll),l&&t(function(){var e=new s(l,o,n,-(r.offset?parseInt(r.offset,10):c));i.addSpy(e),o.$on("$locationChangeSuccess",e.flushTargetCache.bind(e));var t=u.$on("$stateChangeSuccess",e.flushTargetCache.bind(e));o.$on("$destroy",function(){i.removeSpy(e),t()})},0,!1)}}}])});