// gives up and down scroll buttons to images, spans, ... named up_name, down_name, respectively.
// will keep the default scroll_box's style overflow if it encounters errors (so make overflow: auto;)

// usage: put this after the scrollbox div:  
// var div_scroll1 = new Scroller( ) ;
//	div_scroll1.controlId = "scroll1" ;
//	div_scroll1.upControlId = "scroll1_up" ;
//	div_scroll1.downControlId = "scroll1_down" ;
//	div_scroll1.initalise( ) ;
var Scroller				= function ( )
{
	var self				= this ;

	self.base				= BaseClass ;
	self.base( ) ;

	var baseInitalise		= self.initalise ;
	self.name				= "Scroller" ;

	self.controlId			= "" ;
	self.control			= null ;

	self.upControlId		= "" ;
	self.downControlId		= "" ;

	self.scrollCursor		= 0 ;
	self.speed				= 5 ;
	self.timeoutId			= 0 ;

	self.setControls		= function( )
	{
		if ( document.getElementById ) 
		{
			self.control	= document.getElementById( self.controlId ) ;
			if ( self.control )
			{
				self.control.style.overflow = 'hidden';
			}
			var upControl	= document.getElementById( self.upControlId ) ;
			var downControl	= document.getElementById( self.downControlId ) ;

			if ( upControl && downControl ) 
			{
				self.addEvent( upControl , "mouseover" , self.scrollUp ) ;
				self.addEvent( upControl , "mouseout" , self.stopScroll ) ;

				self.addEvent( downControl , "mouseover" , self.scrollDown ) ;
				self.addEvent( downControl , "mouseout" , self.stopScroll ) ;
			}
		}
		return true ;
	} ;

	self.stopScroll			= function( ) 
	{
		clearTimeout( self.timeoutId ) ;
		return				true ;
	} ;

	self.scrollUp			= function( ) 
	{
		if ( self.control ) 
		{
			self.scrollCursor		= ( self.scrollCursor - self.speed ) < 0 ? 0 : self.scrollCursor - self.speed ;
			self.control.scrollTop	= self.scrollCursor ;
			self.timeoutId			= setTimeout( self.scrollUp , 60 ) ;
			return			true ;
		}
		return				false ;
	} ;

	self.scrollDown			= function( ) 
	{
		if ( self.control ) 
		{
			self.scrollCursor		+= self.speed ;
			self.control.scrollTop	= self.scrollCursor ;
			self.timeoutId			= setTimeout( self.scrollDown , 60 ) ;
			return			true ;
		}
		return				false ;
	} ;

	self.resetScroll		= function( ) 
	{
		if ( self.control ) 
		{
			self.control.scrollTop	= 0 ;
			self.scrollCursor		= 0 ;
			return			true ;
		}
		return				false ;
	} ;

	self.initalise			= function( )
	{
		// Must set the response of this into a variable or the method will itself return true and not continue.
		if ( baseInitalise( ) == false )
		{
			return			false ;
		}
		if ( self.setControls( ) == false )
		{
			return			false ;
		}
		return				true ;
	} ;

	// Object created OK	
	return					true;
} ;

