var Qcarousel =
{
	listIndex: 0,
	listCount: 0,
	animationInProgress: false,
	
	extendElement: function()
	{
		Element.addMethods({
			disable: function(el)
			{
				el = $(el);
				el.setStyle({ opacity: 0.5, cursor: 'default' });
			},
			
			enable: function(el)
			{
				el = $(el);
				el.setStyle({ opacity: 1.0, cursor: 'pointer' });
			}
		});
	},
	
	initialize: function(leftArrow, rightArrow, list)
	{
		this.extendElement();
		
		var _this = this;
		_this.listCount = $(list).childElements().length;
		
		$(leftArrow).disable();
		
		$(rightArrow).observe('click', function(e)
		{
			if((_this.listIndex + 1) < _this.listCount && !_this.animationInProgress)
			{
				_this.animationInProgress = true;
				var w = this.up('div').down('ul').down('li').getWidth();
				new Effect.Move(this.up('div').down('ul'),
				{
					x: -w,
					duration: 0.3,
					afterFinish: function(e)
					{
						_this.listIndex++;
						_this.animationInProgress = false;
						if((_this.listIndex + 1) == _this.listCount)
							$(rightArrow).disable();
						if(_this.listIndex > 0)
							$(leftArrow).enable();
					}
				});
			}
		}),
		
		$(leftArrow).observe('click', function(e)
		{
			if(_this.listIndex > 0 && !_this.animationInProgress)
			{
				_this.animationInProgress = true;
				var w = this.up('div').down('ul').down('li').getWidth();
				new Effect.Move(this.up('div').down('ul'),
				{
					x: w,
					duration: 0.3,
					afterFinish: function(e)
					{
						_this.listIndex--;
						_this.animationInProgress = false;
						if((_this.listIndex + 1) < _this.listCount)
							$(rightArrow).enable();
						if(_this.listIndex == 0)
							$(leftArrow).disable();
					}
				});
			}
		})
	}
}
