var coScroller = {
	Slider: function(container,item,limit,prev,next){
		coScroller._init(container,item,limit,true,prev,next,0);
	},
	
	Slider2: function(container,item,limit,prev,next){
		coScroller._init(container,item,limit,false,next,prev,$ES(item,container).length-1);
	},
		
    _init: function(container,item,limit,checkLimit,prev,next,step){
		var scroller = new Fx.Scroll(container, {
			wait: false,
			duration: 800,
			transition: Fx.Transitions.Cubic.easeInOut
		});
		
		var scroller2 = new Fx.Scroll(container, {
			wait: false,
			duration: 1,
			transition: Fx.Transitions.Cubic.easeInOut
		});
		
		scroller2.toElement($ES(item,container)[step]);
		
		if(checkLimit) coScroller._checkLimit(container,item,limit,prev,next,step);
		
		$(next).addEvent('click', function(event) {
			if (step < ($ES(item,container).length-limit)) step++;
			coScroller._checkLimit(container,item,limit,prev,next,step);
			event = new Event(event).stop();
			scroller.toElement($ES(item,container)[step]);
		});
		
		$(prev).addEvent('click', function(event) {
			if (step > 0 ) step--;
			coScroller._checkLimit(container,item,limit,prev,next,step);
			event = new Event(event).stop();
			scroller.toElement($ES(item,container)[step]);
		});
    },
	
	_checkLimit: function(container,item,limit,prev,next,step) {
		if (step == $ES(item,container).length-limit || $ES(item,container).length < limit) $(next).setOpacity(0.0);
		else $(next).setOpacity(1);
			
		if (step == 0) $(prev).setOpacity(0.0);
		else $(prev).setOpacity(1);
	}
};

/*var coAutoScroller = {
	_go: function(container,item,limit) {
		var step = $('step').getProperty('rel');
		var container = 'autoScroll';
		var item = 'td';
		var limit = 0;
		
		var autoScroller = new Fx.Scroll(container, {
			wait: false,
			duration: 800,
			transition: Fx.Transitions.Cubic.easeInOut
		});
		
		if (step == $ES(item,container).length-limit-1 || $ES(item,container).length < limit) dir=1;
		else if (step == 0) dir=0;
		
		if (dir == 0) {
			if (step < ($ES(item,container).length-limit)) step++;
			$('step').setProperty('rel',step);
		}
		else if (dir == 1) {
			if (step > 0 ) step--;
			$('step').setProperty('rel',step);
		}
		
		autoScroller.toElement($ES(item,container)[step]);
	}
};*/
var coAutoScroller = {
	_go: function() {
		var step = $('step').getProperty('rel');
		var container = 'autoScroll';
		var item = 'td';
		var limit = 1;
		
		var autoScroller = new Fx.Scroll(container, {
			wait: false,
			duration: 800,
			transition: Fx.Transitions.Cubic.easeInOut
		});
		
		if (step < ($ES(item,container).length-limit)) {
			step++;
			$('step').setProperty('rel',step);
			autoScroller.toElement($ES(item,container)[step]);
		}		
	}
};


var OFFECCT = {
	start: function(){	
		if ($('splitScroll')) {
			coScroller.Slider('splitScroll','td',1,'leftscroll','rightscroll');
			if ($('footer')) {
				coScroller.Slider2('footer','td',1,'leftscroll','rightscroll');
			}
		}
		if ($('footerScroll')) {
			coScroller.Slider('footerScroll','td',1,'leftscroll','rightscroll');
		}
		if ($('autoScroll')) {
			coAutoScroller._go.periodical(6000);
		}
	}
}

window.addEvent('load', OFFECCT.start);
