fx.Background = Class.create();
fx.Background.prototype = Object.extend(new fx.Base(), {

	initialize: function(el, options)
	{
		this.el = $(el);
		this.setOptions(options);
	},
	increase: function()
	{
		this.el.style.marginLeft = this.now + "px";						
	},
	scroll: function(howMuch, jump, total)
	{	
		// jump must be a valid integer and above 1
		if (/^[1-9][0-9]*$/.test(jump) == false) jump = 1;
		
		if (/^-?[0-9]+$/.test(this.now))
		{ 
			this.clearTimer();

			var full_width = this.el.offsetWidth;
			var window_width = this.el.parentNode.offsetWidth;

			// calculate the width of elements, including padding/border								
			var scroll_limit = full_width - window_width;
		
			//alert("\nfull_width: " + full_width	+ "\nwindow_width: " + window_width  + "\nthis.now: " + this.now + "\nhowMuch: " + howMuch + "\nscroll_limit: " + scroll_limit + "\nthis.now+scroll_limit: " + (Math.abs(this.now) + scroll_limit) + "\njump: " + jump);	
			
			// a minus number is considered "backwards" and "forward" is a positive
			if (/^-/.test(howMuch))
			{
				// calculate the maximum we can go forward by, if it's above the "jump" it doesn't matter
				var potential_jump = Math.abs((Math.abs(scroll_limit)-Math.abs(this.now)) / howMuch);
				// if the potential jump is below the "jump" then we need to reduce the jump so it doesn't slide into empty items
				if (potential_jump < jump) jump = potential_jump;
				// if the potential_jump goes below/equal 0 be know not to go any further, we are at the start
				if (potential_jump <= 0) jump = 0;
			}
			else
			{	
				// calculate how far we can go back by
				var potential_jump = (this.now+(jump*howMuch));			
				// finalize the potential_jump by work out what distance we have left before we hit zero
					potential_jump = ((window_width-potential_jump) / howMuch);	
				// if the potential jump is below the "jump" then we need to reduce the jump so it doesn't slide into empty items
				if (potential_jump < jump) jump = potential_jump;
				// if the potential_jump goes below/equal 0 be know not to go any further, we are at the start
				if (potential_jump <= 0) jump = 0;
			}

			// extend the distance to travel if the jump is more than 1
			howMuch *= jump;

			if ((this.now+howMuch) > 0) howMuch = Math.abs(this.now);

			this.custom(this.now, this.now + howMuch);
		}	
	}
		
});

window.onload = function() {		

	myNewEffect = new fx.Background('scroller_members', {duration: 500});
	
}