// Mosodofu.net/Lemuel.nl Scrolling Class
// copyright 2008 Jonathan Tamboer

var Scrolling = Class.create();

Scrolling.prototype = {

	initialize: function(id, element, blockCount, blockWidth, blockId, jumpsPath)
	{
		this.id = id;
		this.element = element;
		this.blockCount = blockCount;
		this.blockWidth = blockWidth;
		this.blockId = blockId;
		this.jumpsPath = '/';
		this.jumps = false;		
		
		if(jumpsPath)
		{
			this.jumpsPath = jumpsPath;
			this.jumps = true;
		}
		
		if(this.blockId > 1)
		{
			var newX = (this.blockId - 1) * this.blockWidth;
			$(this.element).setStyle({'left': '-' + newX + 'px'});
		}
		
		if(this.jumps && this.blockCount > 1)
		{
			var jumpDump = '';
			for (var i = 1; i <= this.blockCount; i++)
			{
				jumpDump += '<em id="jump_' + i + '" onclick="' + this.id + '.goTo(' + i + ');"><img src="' + this.jumpsPath + 'img/blank.gif" /></em>';
			}			
			Element.insert('thumbs_jump', jumpDump);
			$('jump_' + this.blockId).addClassName('jump_here');
		}
		
	},

	goTo: function(blockId)
	{
		if(blockId <= this.blockCount && blockId >= 1)
		{
			this.blockId = blockId;
			var newX = (this.blockId - 1) * this.blockWidth * -1;
			new Effect.Move(this.element, {x: newX, y: 0, fps: 80, mode: 'absolute', queue: { position: 'end', scope: this.id, limit: 11}});
			
			if(this.jumps)
			{
				$('thumbs_jump').select('em').each(function(item){item.removeClassName('jump_here');});
				$('jump_' + this.blockId).addClassName('jump_here');
			}
		}
	},

	goNext: function()
	{
		if(this.blockId < this.blockCount)
		{
			this.blockId = this.blockId + 1;
		}
		else
		{
			this.blockId = 1;
		}	
		this.goTo(this.blockId);
	},
	
	goPrev: function()
	{
		if(this.blockId > 1)
		{
			this.blockId = this.blockId - 1;
		}
		else
		{
			this.blockId = this.blockCount;
		}	
		this.goTo(this.blockId);
	}
}
