// JavaScript Document

function ContinuousScroller(scrollSpeed,scrollElements){
	this.scrollSpeed = scrollSpeed;
	this.scrollElement = scrollElements
	this.start();

}

ContinuousScroller.prototype.start = function(){
	var resetScroll = new Fx.Scroll('scrollingFeature', {
		wait: false,
		duration: 1000,
		offset: {'x': 0, 'y': 0},
		transition: Fx.Transitions.linear
	});
	
	
	//resetScroll.toElement('movie1');
	
	var scroll = new Fx.Scroll('scrollingFeature', {
		wait: false,
		duration: this.scrollSpeed,
		offset: {'x': 0, 'y': 0},
		transition: Fx.Transitions.linear
	});
	
	
	function scrollFeatures(interval,scrollSpeed){
		scroll.toElement('movie1');
	}
	
	resetScroll.set(0,0);
	resetScroll.stop();
	function transitionScroll(step,scrollSpeed,maxEl){
		var maxStep = maxEl;
		var previousStep = step-1;
		var nextStep = step+1;
		if(previousStep<1){
			previousStep = maxStep;
		}
		if(nextStep>maxStep){
			nextStep = 1;
		}
		
		var resetScroll = new Fx.Scroll('scrollingFeature', {
			wait: false,
			duration: 1000,
			offset: {'x': 0, 'y': 0},
			transition: Fx.Transitions.linear
		});
		
		var oldMovie = $('movie'+previousStep);
		var movie = oldMovie.clone().cloneEvents(oldMovie);
		oldMovie.remove();
		resetScroll.set(0,0);
		movie.injectBefore('movieBreak');
		
					
	
		var nextScroll = new Fx.Scroll('scrollingFeature', {
			wait: false,
			duration: scrollSpeed,
			offset: {'x': 0, 'y': 0},
			transition: Fx.Transitions.linear
		});
		
		nextScroll.toElement('movie'+(nextStep));
		transitionScroll.delay(scrollSpeed,this,[nextStep,scrollSpeed,maxEl])
	}
	
	transitionScroll(1,this.scrollSpeed,this.scrollElement.length);
}