/**
 * jQuery.SerialScroll - Animated scrolling of series
 * Copyright (c) 2007-2008 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 8/3/2008
 * @author Ariel Flesler
 * @version 1.1.2
 *
 * http://flesler.blogspot.com/2008/02/jqueryserialscroll.html
 */
;(function($){
	var a='serialScroll',b='.'+a,c='bind',u=$[a]=function(b){
		$.scrollTo.window()[a](b)
	};
	u.defaults={duration:1000,axis:'x',event:'click',start:0,step:1,lock:1,cycle:1};
	$.fn[a]=function(q){
		q=$.extend({},u.defaults,q);
		var r=q.event,s=q.step,t=q.duration/s;
		return this.each(function(){
			var h=$(this),j=q.lazy?q.items:$(q.items,h),k=q.start,l;
			if(q.force)n.call(this,{},k);
			$(q.prev||[])[c](r,-s,m);
			$(q.next||[])[c](r,s,m);
			h[c]('prev'+b,-s,m)[c]('next'+b,s,m)[c]('goto'+b,n)[c]('start'+b,function(e,i){
				if(!q.interval){q.interval=i||1000;p();o()}
			})[c]('stop'+b,function(){p();q.interval=0});
			if(!q.lazy&&q.jump)j[c](r,function(e){e.data=j.index(this);n(e,this)});
			function m(e){e.data+=k;n(e,this)};
			function n(e,a){
				if(typeof a=='number'){e.data=a;a=this}
				var b=e.data,c,d=e.type,f=$(j,h),g=f.length;
				if(d)e.preventDefault();
				b%=g;
				var b2=b;
				var k2=k;
				if(b<0){
					b+=g;
				}
				var b1=0;
				var k1=0;
				if(b==g-2 && k==g-1){
					b1=g-1;
					k1=g-2;
				}
				if(b==1 && k==0){
					b1=0;
					k1=1;
				}
				c=f[b];
				if(q.interval){p();l=setTimeout(o,q.interval)}
				if(isNaN(b)||d&&k==b||q.lock&&h.is(':animated')||!q.cycle&&!f[e.data]||d&&q.onBefore&&q.onBefore.call(a,e,c,h,f,b)===!1)return;
				if(q.stop)h.queue('fx',[]).stop();
				q.duration=Math.abs(t*(k-b));
				h.scrollTo(c,q);
				k=b;
				if((b2==0 && k2==g-1) || (b2==-1 && k2==0)){
					iNum=-1;
				}
				if(b1+k1>0 && iNum==-1){
					c=f[b1];
					if(q.interval){p();l=setTimeout(o,q.interval)}
					if(isNaN(b1)||d&&k1==b1||q.lock&&h.is(':animated')||!q.cycle&&!f[e.data]||d&&q.onBefore&&q.onBefore.call(a,e,c,h,f,b1)===!1)return;
					if(q.stop)h.queue('fx',[]).stop();
					q.duration=Math.abs(t*(k1-b1));
					h.scrollTo(c,q);
					b=k1;
					k=b1;
					iNum=0;
				}
			};
			function o(){h.trigger('next'+b)};
			function p(){clearTimeout(l)}
		})
	}
})(jQuery);

var iNum=0;