/* 	Scroll vertical automatique des liens
	Par Jautée William
	http://www.seyartdesign.fr
	version 0.2
								*/
								
var scrollLinksFct = function(){
	
	var tabElements = new Array();
	$each($$('.scrolllinks'),function(item,i){
		tabElements[i] = item;
									 });
	
	var scrollLinks = new Class({
		initialize : function(elt){
			this.elt = elt;
			this.duree = 500;
			this.posY = (window.getSize().y/2)-150;
			this.elt.setStyle('top',this.posY+'px');
			this.Fxscroll = new Fx.Tween(elt,{
				duration : this.duree,
				transition: 'linear',
				link:'cancel'
			});
		},
		move : function(){
			this.posYnew = $(document.body).getScroll().y + (window.getSize().y/2)-150;
			this.posYnew = Math.max(this.posYnew,0);
			this.posYnew = Math.min(document.getElement('article').getSize().y-100,this.posYnew);
			this.Fxscroll.start('top', this.posYnew+'px');	
		}
								
	});	
	
	var tabElementsObj = new Array();
	
	for (i=0; i<tabElements.length ; i++) {
		tabElementsObj[i] = new scrollLinks(tabElements[i]);
	}
	
	var scrollRestart = function() {
		for (i=0; i<tabElementsObj.length ; i++) {
			tabElementsObj[i].move();
		}			
	}
	
	
	var scrollTimer = 0;
		
	var reCalculateScroll = function(){
		if (scrollTimer)
			clearTimeout(scrollTimer);
	
		scrollTimer = setTimeout(scrollRestart, 500);
	}
		
	window.addEvent('scroll', reCalculateScroll); 
	
	
	
}
