/**
 * jQuery.ScrollTo
 * Copyright (c) 2007 Ariel Flesler - aflesler(at)gmail(dot)com
 * Licensed under GPL license (http://www.opensource.org/licenses/gpl-license.php).
 * Date: 11/16/2007
 *
 * @projectDescription Easy element scrolling using jQuery.
 * Compatible with jQuery 1.2.1, tested on Firefox 2.0.0.7, and IE 6, both on Windows.
 *
 * @author Ariel Flesler
 * @version 1.2.4
 *
 * @id jQuery.fn.scrollTo
 * @param {String|Number|DOMElement|jQuery} target Where to scroll the matched elements.
 *	  The different options for target are:
 *		- A number position (will be applied to all axes).
 *		- A string position ('44', '100px', '+=90', etc ) will be applied to all axes
 *		- A jQuery/DOM element ( logically, child of the element to scroll )
 *		- A string selector, that will be relative to the element to scroll ( 'li:eq(2)', etc )
 *		- A hash { top:x, left:y }, x and y can be any kind of number/string like above.
 * @param {Object} settings Hash of settings, optional.
 *	 @option {String} axis Which axis must be scrolled, use 'x', 'y', 'xy' or 'yx'.
 *	 @option {Number} speed The OVERALL length of the animation.
 *	 @option {String} easing The easing method for the animation.
 *	 @option {Boolean} margin If true, the margin of the target element will be deducted from the final position.
 *	 @option {Object|Number} offset Add/deduct from the end position. One number for both axis or { top:x, left:y }
 *	 @option {Boolean} queue If true, and both axis are given, the 2nd axis will only be animated after the first one ends.
 *	 @option {Function} onAfter Function to be called after the scrolling ends.
 *	 @option {Function} onAfterFirst If queuing is activated, this function will be called after the first scrolling ends.
 * @return {jQuery} Returns the same jQuery object, for chaining.
 *
 * @example $('div').scrollTo( 340 );
 *
 * @example $('div').scrollTo( '+=340px', { axis:'y' } );
 *
 * @example $('div').scrollTo( 'p.paragraph:eq(2)', { speed:500, easing:'swing', queue:true, axis:'xy' } );
 *
 * @example var second_child = document.getElementById('container').firstChild.nextSibling;
 *			$('#container').scrollTo( second_child, { speed:500, axis:'x', onAfter:function(){
 *				alert('scrolled!!');
 *			}});
 *
 * @example $('div').scrollTo( { top: 300, left:'+=200' }, { offset:-20 } );
 *
 * Notes:
 *  - jQuery.scrollTo will make the whole window scroll, it accepts the same parameters as jQuery.fn.scrollTo.
 *  - The plugin no longer requires Dimensions.
 *	- If you are interested in animated "same-page-scrolling" using anchors, check http://jquery.com/plugins/project/LocalScroll.
 *	- The option 'margin' won't be valid, if the target is an absolute position.
 *	- The option 'queue' won't be taken into account, if only 1 axis is given.

 **/(function(a){a.scrollTo=function(c,b){return a("html,body").scrollTo(c,b)};a.scrollTo.defaults={axis:"y",speed:1};a.fn.scrollTo=function(c,b){b=a.extend({},a.scrollTo.defaults,b);b.queue=b.queue&&b.axis.length==2;if(b.queue){b.speed=Math.ceil(b.speed/2)}if(typeof b.offset=="number"){b.offset={left:b.offset,top:b.offset}}return this.each(function(){var e=a(this),k=c,l,h={};switch(typeof k){case"number":case"string":if(/^([+-]=)?\d+(px)?$/.test(k)){k={top:k,left:k};break}k=a(k,this);case"object":if(k.is||k.style){l=(k=a(k)).offset()}}var f=a(this).offset().top;var i=f+a(this).height();var j=a(this).height();a.each(b.axis.split(""),g);d(b.onAfter);function g(o,p){var q=p=="x"?"Left":"Top",r=q.toLowerCase(),n="scroll"+q,m=e[0][n];delete h[n];h[n]=l?l[r]+(e.is("html,body")?0:m-e.offset()[r]):k[r];if(b.margin&&k.css){h[n]-=parseInt(k.css("margin"+q))||0}if(b.offset&&b.offset[r]){h[n]+=b.offset[r]}if(h[n]>m&&h[n]<(m+j-(k.height()+20))){delete h[n]}if(!o&&b.queue){if(m!=h[n]){d(b.onAfterFirst)}delete h[n]}}function d(m){e.animate(h,b.speed,b.easing,function(){if(m){m.call(this,e,h,k)}})}})}})(jQuery);(function(a){a.scrollTo=function(c,b){return a("html,body").scrollTo(c,b)};a.scrollTo.defaults={axis:"y",speed:1};a.fn.scrollTo=function(c,b){b=a.extend({},a.scrollTo.defaults,b);b.queue=b.queue&&b.axis.length==2;if(b.queue){b.speed=Math.ceil(b.speed/2)}if(typeof b.offset=="number"){b.offset={left:b.offset,top:b.offset}}return this.each(function(){var e=a(this),k=c,l,h={};switch(typeof k){case"number":case"string":if(/^([+-]=)?\d+(px)?$/.test(k)){k={top:k,left:k};break}k=a(k,this);case"object":if(k.is||k.style){l=(k=a(k)).offset()}}var f=a(this).offset().top;var i=f+a(this).height();var j=a(this).height();a.each(b.axis.split(""),g);d(b.onAfter);function g(o,p){var q=p=="x"?"Left":"Top",r=q.toLowerCase(),n="scroll"+q,m=e[0][n];delete h[n];h[n]=l?l[r]+(e.is("html,body")?0:m-e.offset()[r]):k[r];if(b.margin&&k.css){h[n]-=parseInt(k.css("margin"+q))||0}if(b.offset&&b.offset[r]){h[n]+=b.offset[r]}if(h[n]>m&&h[n]<(m+j-(k.height()+20))){delete h[n]}if(!o&&b.queue){if(m!=h[n]){d(b.onAfterFirst)}delete h[n]}}function d(m){e.animate(h,b.speed,b.easing,function(){if(m){m.call(this,e,h,k)}})}})}})(jQuery);
