﻿/*
 * jQuery scrollintoview() plugin and :scrollable selector filter
 *
 * Version 1.8.a (5 May 2012)
 * Requires jQuery 1.4 or newer
 *
 * Copyright (c) 2011 Robert Koritnik
 * Licensed under the terms of the MIT license
 * http://www.opensource.org/licenses/mit-license.php
 *
 * Modified by Alex King to add vertical offset support.
 */
(function(f){var k={vertical:{x:!1,y:!0},horizontal:{x:!0,y:!1},both:{x:!0,y:!0},x:{x:!0,y:!1},y:{x:!1,y:!0}},o={duration:"fast",direction:"both",offset:0},l=/^(?:html)$/i,m=function(a){var b=f(window),c=l.test(a[0].nodeName),e;if(c)e={top:0,left:0,bottom:0,right:0};else{var d=a[0],i;i=document.defaultView&&document.defaultView.getComputedStyle?document.defaultView.getComputedStyle(d,null):d.currentStyle;var h=document.defaultView&&document.defaultView.getComputedStyle?!0:!1;e=parseFloat(h?i.borderTopWidth:
f.css(d,"borderTopWidth"))||0;var g=parseFloat(h?i.borderLeftWidth:f.css(d,"borderLeftWidth"))||0,j=parseFloat(h?i.borderBottomWidth:f.css(d,"borderBottomWidth"))||0,d=parseFloat(h?i.borderRightWidth:f.css(d,"borderRightWidth"))||0;e={top:e,left:g,bottom:j,right:d,vertical:e+j,horizontal:g+d}}b={top:(c?b:a).scrollTop(),left:(c?b:a).scrollLeft()};g={right:c?0:a.innerWidth()-a[0].clientWidth,bottom:c?0:a.innerHeight()-a[0].clientHeight};j=a[0].getBoundingClientRect();return{border:e,scroll:b,scrollbar:g,
rect:{top:c?0:j.top,left:c?0:j.left,bottom:c?a[0].clientHeight:j.bottom,right:c?a[0].clientWidth:j.right}}};f.fn.extend({scrollintoview:function(a){a=f.extend({},o,a);a.direction=k["string"===typeof a.direction&&a.direction.toLowerCase()]||k.both;var b="";!0===a.direction.x&&(b="horizontal");!0===a.direction.y&&(b=b?"both":"vertical");var c=this.eq(0),e=c.closest(":scrollable("+b+")");if(0<e.length){var e=e.eq(0),d=m(c),b=m(e),c=d.rect.top-(b.rect.top+b.border.top),i=b.rect.bottom-b.border.bottom-
b.scrollbar.bottom-d.rect.bottom,h=d.rect.left-(b.rect.left+b.border.left),d=b.rect.right-b.border.right-b.scrollbar.right-d.rect.right,g={};!0===a.direction.y&&(c<0+a.offset?g.scrollTop=b.scroll.top+c-a.offset:c>0+a.offset&&i<0-a.offset&&(g.scrollTop=b.scroll.top+Math.min(c,-i+a.offset)));!0===a.direction.x&&(0>h?g.scrollLeft=b.scroll.left+h:0<h&&0>d&&(g.scrollLeft=b.scroll.left+Math.min(h,-d)));f.isEmptyObject(g)?f.isFunction(a.complete)&&a.complete.call(e[0]):(l.test(e[0].nodeName)&&(e=f("html,body")),
e.animate(g,a.duration).eq(0).queue(function(b){f.isFunction(a.complete)&&a.complete.call(e[0]);b()}))}return this}});var n={auto:!0,scroll:!0,visible:!1,hidden:!1};f.extend(f.expr[":"],{scrollable:function(a,b,c){var b=k["string"===typeof c[3]&&c[3].toLowerCase()]||k.both,c=document.defaultView&&document.defaultView.getComputedStyle?document.defaultView.getComputedStyle(a,null):a.currentStyle,e=n[c.overflowX.toLowerCase()]||!1,d=n[c.overflowY.toLowerCase()]||!1,f=l.test(a.nodeName);if(!e&&!d&&!f)return!1;
a={height:{scroll:a.scrollHeight,client:a.clientHeight},width:{scroll:a.scrollWidth,client:a.clientWidth},scrollableX:function(){return(e||f)&&this.width.scroll>this.width.client},scrollableY:function(){return(d||f)&&this.height.scroll>this.height.client}};return b.y&&a.scrollableY()||b.x&&a.scrollableX()}})})(jQuery);