var actionsBlocked = false;
var TopProducts = Class.create({

	holder 			: null,
	left 			: null,
	right 			: null,
	
	currentStep 	: 1,
	
	step			: 0,
	nrSteps			: 0,
		
	
	initialize :
	function ( holderID, step, nrSteps, leftID, rightID )
	{
		var intialize = 'Just for eclipse';

		this.holder	= $(holderID);
		
		this.holder.style.width = ( step * nrSteps ) + "px";
		this.left	= $(leftID);
		this.right	= $(rightID);
		
		this.step	= step;
		this.nrSteps= nrSteps;
		
		this.initializeEvents();
		
		this.checkArrows();
	},
	
	initializeEvents:
	function ()
	{
		this.left.observe( "click", this.onClickLeftArrow.bind(this));
		this.right.observe( "click", this.onClickRightArrow.bind(this));
	}
	,
	
	onClickLeftArrow:
	function( event )
	{
		if( actionsBlocked ) return;
		
		if( this.currentStep == 1 )
		{
			return;
		}
		else
		{
			this.currentStep--;
			this.checkArrows();
			var thisObject = this;
			
			new Effect.Move( thisObject.holder.id, 
				{
  					x: thisObject.step, y: 0, mode: 'relative'
				}
			);
			actionsBlocked = true;
			setTimeout( 'actionsBlocked = false;', 1000 );
			//transition: Effect.Transitions.spring

		}
	},
	
	onClickRightArrow:
	function( event )
	{
		if( actionsBlocked ) return;
		
		if( this.currentStep == this.nrSteps )
		{
			return;
		}
		else
		{
			
			this.currentStep++;
			this.checkArrows();
			var thisObject = this;
			new Effect.Move( thisObject.holder.id, 
				{
  					x: -1 * thisObject.step, y: 0, mode: 'relative'
				}
			);
			actionsBlocked = true;
			setTimeout( 'actionsBlocked = false;', 1000 );
			

		}
		
	},
	
	checkArrows:
	function( )
	{
		if( this.currentStep == this.nrSteps )
		{
			this.right.className = "goRightOff";			
		}
		else
		{
			this.right.className = "goRight"
		}
		
		if( this.currentStep == 1 )
		{
			this.left.className = "goLeftOff";			
		}
		else
		{
			this.left.className = "goLeft"
		}
		
	}
});