﻿(function(a){var b=a.scrollTo=function(b,d,c){a(window).scrollTo(b,d,c)};b.defaults={axis:"xy",duration:parseFloat(a.fn.jquery)>=1.3?0:1};b.window=function(){return a(window).scrollable()};a.fn.scrollable=function(){return this.map(function(){var b=this,d=!b.nodeName||a.inArray(b.nodeName.toLowerCase(),["iframe","#document","html","body"])!=-1;if(!d)return b;var c=(b.contentWindow||b).document||b.ownerDocument||b;return a.browser.safari||c.compatMode=="BackCompat"?c.body:c.documentElement})};a.fn.scrollTo=function(f,e,d){if(typeof e=="object"){d=e;e=0}if(typeof d=="function")d={onAfter:d};if(f=="max")f=9e9;d=a.extend({},b.defaults,d);e=e||d.speed||d.duration;d.queue=d.queue&&d.axis.length>1;if(d.queue)e/=2;d.offset=c(d.offset);d.over=c(d.over);return this.scrollable().each(function(){var h=this,i=a(h),b=f,j,g={},k=i.is("html,body");switch(typeof b){case "number":case "string":if(/^([+-]=)?\d+(\.\d+)?(px)?$/.test(b)){b=c(b);break}b=a(b,this);case "object":if(b.is||b.style)j=(b=a(b)).offset()}a.each(d.axis.split(""),function(p,f){var e=f=="x"?"Left":"Top",c=e.toLowerCase(),a="scroll"+e,n=h[a],o=f=="x"?"Width":"Height";if(j){g[a]=j[c]+(k?0:n-i.offset()[c]);if(d.margin){g[a]-=parseInt(b.css("margin"+e))||0;g[a]-=parseInt(b.css("border"+e+"Width"))||0}g[a]+=d.offset[c]||0;if(d.over[c])g[a]+=b[o.toLowerCase()]()*d.over[c]}else g[a]=b[c];if(/^\d+$/.test(g[a]))g[a]=g[a]<=0?0:Math.min(g[a],m(o));if(!p&&d.queue){if(n!=g[a])l(d.onAfterFirst);delete g[a]}});l(d.onAfter);function l(a){i.animate(g,e,d.easing,a&&function(){a.call(this,f,d)})}function m(b){var a="scroll"+b;if(!k)return h[a];var d="client"+b,e=h.ownerDocument.documentElement,c=h.ownerDocument.body;return Math.max(e[a],c[a])-Math.min(e[d],c[d])}}).end()};function c(a){return typeof a=="object"?a:{top:a,left:a}}})(jQuery)