// Copyright (c) 2010
//

var Scrollers = Class.create({
	
	initialize: function( obj, options ) {

	    this.options = options || { };
		
		this.obj 		= obj;

		this.currpos 	= 0;
		this.total 		= this.options.total;
		this.perpage 	= this.options.perpage;
		this.inc 		= this.options.inc;
		
		this.fwd 		= this.options.fwd;
		this.rwd 		= this.options.rwd;
		this.vertical	= this.options.vertical;
		this.navctrl	= this.options.navctrl;
		this.wheel		= ( this.options.wheel != false );
		
		var ref = this;
		
		if( this.total > this.perpage ) {
			
			$( this.navctrl ).appear( {duration:.5} );
			disableButton( this.fwd );

			Event.observe( $( this.fwd ), 'click', function() {
				ref.slide( -1 );
			});
			
			Event.observe( $( this.rwd ), 'click', function() {
				ref.slide( 1 );
			});
			
			if( this.wheel ) {
				Event.observe( this.obj, 'mousewheel', function(e) {
					ref.slide(  -Event.wheel(e) );
					Event.stop(e);
				});
				Event.observe( this.obj, 'DOMMouseScroll', function(e) {
					ref.slide(  -Event.wheel(e) );
					Event.stop(e);
				});
			}

		}

	},
	
	handlewheel: function( e ) {
		ref.slide(  Event.wheel(e) );
	},
	
	slide: function( dir ) {
		if( this.currpos + dir >= 0 && this.currpos + dir <= this.total-this.perpage ) {
			
			this.currpos += dir;
			
			new Effect.Move( this.obj, { x:(!this.vertical)?-this.currpos*this.inc:0, y:(this.vertical)?-this.currpos*this.inc:0, mode: 'absolute', duration:.5} );
			
			if( this.currpos == 0 ) disableButton( this.fwd );
			if( this.currpos == 1 ) enableButton( this.fwd );
			
			if( this.currpos == this.total-this.perpage ) disableButton( this.rwd );
			else enableButton( this.rwd );

		}
	}
	
});

/*
*/