/*
me : vivpascal (vivepascal[@]wanadoo[.]fr)
date: 11/01/2008
This script is an degradation from  : Smooth Scroller Script, version 1.0.1 (c) 2007 Dezinerfolio Inc. <midart@gmail.com>
thanks to Dezinerfolio !
I change it in some peaces because the original script had problem with mootools scripts and anchors (it detected them which caused problems).

PURPOSE AND USE
Scroll smoothly to a anchor (<a name="xxx"/></a>)
You can launch it like this = <a href="javascript:vp_scroller.action('top30');">haut de page</a>, 'top30' is the name of the anchor you want to reach
That's all.

*/
vp_scroller = {
	speed:10,
	
	gy: function (d) {
		gy = d.offsetTop
		if (d.offsetParent) while (d = d.offsetParent) gy += d.offsetTop
		return gy
	},
	// returns the current scroll position
	scrollTop: function (){
		body=document.body
			d=document.documentElement
			if (body && body.scrollTop) return body.scrollTop
			if (d && d.scrollTop) return d.scrollTop
			if (window.pageYOffset) return window.pageYOffset
			return 0
	},
	
	scroll : function (d){
		i = window.innerHeight || document.documentElement.clientHeight;
		h=document.body.scrollHeight;
		a = vp_scroller.scrollTop()
		if(d>a)
			if(h-d>i)
				a+=Math.ceil((d-a)/vp_scroller.speed)
			else
				a+=Math.ceil((d-a-(h-d))/vp_scroller.speed)
		else
			a = a+(d-a)/vp_scroller.speed;
		window.scrollTo(0,a)
			if(a==d || vp_scroller.offsetTop==a){clearInterval(vp_scroller.interval);}
			vp_scroller.offsetTop=a
	},
	
	action: function(d){
		var x = document.getElementsByName(d)[0];
		vp_scroller.interval = setInterval('vp_scroller.scroll('+vp_scroller.gy(x)+')',10);
	}
}