/*Scroller2: Bases on the mootools scroller by mootools
By; Frank Teunisse


	<script type="text/javascript" src="js/scroller.js"></script>
	<script type="text/javascript">
	var scroll2
	
	function initScroll() {
		scroll2 = new Scroller2(\'nieuwsitemcontainer\', {area: 160, velocity: 0.1, name: \'scroll2\', scrolltime: 2000, scrollinterval: 4000});

		// Mousemove
		$(\'nieuwsitemcontainer\').addEvent(\'mouseenter\', scroll2.start.bind(scroll2));
		$(\'nieuwsitemcontainer\').addEvent(\'mouseleave\', scroll2.stop.bind(scroll2));
	}
	
	window.addEvent(\'domready\', function(){
		initScroll();
	});
	
	</script>
	
	
*/
var Scroller3 = new Class({

	options: {
		autoscrolldelta: 162,
		scrolltime: 2000,
		scrollinterval: 4000,
		name: "scroll3"

	},

	initialize: function(element, options){
		var elementname = element;
		this.setOptions(options);
		this.element = $(element);
		
		//Scroll naar boven
		var el = this.element.getSize();
		el.scroll.y = 0;
		
		this.autoscrolldelta = this.options.autoscrolldelta;
		
		this.timeout = window.setTimeout(this.options.name+'.autoscroll()',this.options.scrollinterval);
		//this.mousemover = ([window, document].contains(element)) ? $(document.body) : this.element;
		
		this.scrollfx = new Fx.Scroll(elementname, {
		wait: false,
		duration: this.options.scrolltime,
		offset: {'x': 0, 'y': 0},
		transition: Fx.Transitions.Sine.easeInOut
		});
		
	},
	
	stop: function (){
		if(!(this.timeout == null)) this.timeout = window.clearTimeout(this.timeout);
	},
	
	scrollto: function (itemnumber){

		this.selectitembutton(itemnumber);
		this.scrollfx.scrollTo(0,this.autoscrolldelta*(itemnumber-1));

	},
	
	start: function (){
		if(this.timeout == null) this.timeout = window.setTimeout(this.options.name+'.autoscroll()',this.options.scrollinterval);
	},
	
	selectitembutton: function (itemnumber){
		itemnumber = itemnumber % 5;
		if(itemnumber==0) itemnumber = 5;
		for(i = 1; i<6; i++)
			{
			if(button = $('scrollitem'+i))
				{
				
				if(i==itemnumber) button.style.fontWeight = "bold";
				else button.style.fontWeight = "normal";
				}
			}
	},
	
	autoscroll: function(){
		var el = this.element.getSize();
		this.selectitembutton(el.scroll['y']/this.autoscrolldelta+2);
		
		//Voor het omkeren
		if(el.scroll['y']+this.autoscrolldelta <= 0) { this.autoscrolldelta = this.options.autoscrolldelta; }
		if(el.scroll['y']+this.autoscrolldelta >= (el.scrollSize['y']-el.size['y'])) this.autoscrolldelta = -10*this.options.autoscrolldelta;
		
		//$('debug').innerHTML= ""+el.scroll['y']+" <br />"+this.autoscrolldelta+" <br />"+(el.scroll['y']+this.autoscrolldelta);
		this.scrollfx.scrollTo(0,el.scroll['y']+this.autoscrolldelta);
		
		this.timeout = window.setTimeout(this.options.name+'.autoscroll()',this.options.scrollinterval);

	}

});

Scroller3.implement(new Events, new Options);