var gn_SCROLL_UP = 0;
var gn_SCROLL_DOWN = 1;
var gn_SCROLL_LEFT = 2;
var gn_SCROLL_RIGHT = 3;

function CScrollBox( sName, nMaskY, nMaskWidth, nMaskHeight, nMaskX )
{
	this.sName = sName;
	this.nMaskY = nMaskY;
	this.nMaskX = nMaskX;
	this.nMaskWidth = nMaskWidth;
	this.nMaskHeight = nMaskHeight;
	this.oDiv = new CDocumentObjectModel("div" + this.sName );
	this.nLayerY = this.oDiv.GetAbsouluteTop();
	this.nLayerX = this.oDiv.GetAbsouluteLeft();
	this.nAcceleration = 0.8;		
	this.nScrollTime = 100;		
	this.nTimeOut = -1;
	
	this.Init = CScrollBox_Init;
	this.ScrollStop = CScrollBox_ScrollStop;
	this.ScrollLayer = CScrollBox_ScrollLayer;		
	this.SetPostion = CScrollBox_SetPostion;
	this.SetSpeed = CScrollBox_SetSpeed;
	this.ScrollToPosition = CScrollBox_ScrollToPosition;	
	
	this.Init();
}

function CScrollBox_Init()
{
	this.oDiv.SetClip( this.nMaskX, this.nMaskY, this.nMaskWidth, this.nMaskHeight );
}


function CScrollBox_ScrollStop( )
{
	clearTimeout( this.nTimeOut );
}

function CScrollBox_SetPostion()
{
		this.oDiv.SetTop( this.nLayerY );
		this.oDiv.SetLeft( this.nLayerX );
		this.oDiv.SetClip( this.nMaskX, this.nMaskY, this.nMaskWidth, this.nMaskHeight );
}

function CScrollBox_SetSpeed( nScroll, nScrollSpeed )
{	
	switch( nScroll )
	{
		case gn_SCROLL_UP:
			this.nMaskY += nScrollSpeed;
			this.nMaskHeight += nScrollSpeed;
			this.nLayerY -= nScrollSpeed;	
		break;
		case gn_SCROLL_DOWN:
			this.nMaskY -= nScrollSpeed;
			this.nMaskHeight -= nScrollSpeed;
			this.nLayerY += nScrollSpeed;	
		break;
		case gn_SCROLL_LEFT:
			this.nMaskX += nScrollSpeed;
			this.nMaskWidth += nScrollSpeed;
			this.nLayerX -= nScrollSpeed;	
		break;
		case gn_SCROLL_RIGHT:
			this.nMaskX -= nScrollSpeed;
			this.nMaskWidth -= nScrollSpeed;
			this.nLayerX += nScrollSpeed;
		break;												
	}	
}

function CScrollBox_ScrollToPosition( nScroll, nPostion )
{		
		var nScrollSpeed = 0;
		
		if( nScroll == gn_SCROLL_LEFT || nScroll == gn_SCROLL_RIGHT )
		{		
			nScrollSpeed = Math.floor( ( nPostion - this.nLayerX ) * this.nAcceleration );
			this.SetSpeed( gn_SCROLL_RIGHT, nScrollSpeed );
		}
		else
		{
			nScrollSpeed = Math.floor( ( nPostion - this.nLayerY ) * this.nAcceleration );
			this.SetSpeed( gn_SCROLL_DOWN, nScrollSpeed );
		}
			
		// window.status = nScrollSpeed;			
		
		this.SetPostion();
		this.ScrollStop();			
		this.nTimeOut = setTimeout( "oScroll" + this.sName + ".ScrollToPosition( " + nScroll + ", " + nPostion + " )", this.nScrollTime );
}

function CScrollBox_ScrollLayer( nScroll, nScrollSpeed )
{		
		nScrollSpeed = parseInt( nScrollSpeed, 10 );
		this.SetSpeed( nScroll, nScrollSpeed );	
		this.SetPostion();	
		this.ScrollStop();
		this.nTimeOut = setTimeout( "oScroll" + this.sName + ".ScrollLayer( " + nScroll + ", " + nScrollSpeed + " )", this.nScrollTime );
}
