//Written by Nathan Faubion: http://n-son.com
//Use this or edit how you want, just give me
//some credit!

function jsScrollerTween (o, t, s) {
	var self = this;
	
	this._tweenTo = function (idElement) {
		/* author : Flo
		*  rajout du calcul de la position de l'élément dont l'id est idElement
		*/
			var coordonnees = getAnchorPosition(idElement);
			y=(coordonnees.y)-280;
		//Fin modifs
		
		if (self._idle) {
			var tHeight = self._parent._src ? self._parent._src.totalHeight : self._parent.totalHeight;
			var vHeight = self._parent._src ? self._parent._src.viewableHeight : self._parent.viewableHeight;
			var scrollY = self._parent._src ? self._parent._src._y : self._parent._y;
			
			if (y < 0) y = 0;
			if (y > tHeight - vHeight) y = tHeight - vHeight;
			
			var dist = y - (-scrollY);
			
			self._inc = 0;
			self._timer = null;
			self._values = [];
			self._idle = false;
			for (var i = 0; i < self.steps.length; i++) {
				self._values[i] = Math.round((-scrollY) + dist * (self.steps[i] / 100));
			}
			self._timer = window.setInterval(function () {
				self._parent.scrollTo(0, self._values[self._inc]);
				if (self._inc == self.steps.length-1) {
					window.clearTimeout(self._timer);
					self._idle = true;
				} else self._inc++;
			}, self.stepDelay);
		}
	};
	this._tweenBy = function (y) {
		var scrollY = self._parent._src ? self._parent._src._y : self._parent._y;
		self._tweenTo(-scrollY + y);
	};
	this._trackTween = function (e) {
		e = e ? e : event;
		self._parent.canScroll = false;
		var curY = e.clientY + document.body.scrollTop;
		self._tweenTo((curY - self._parent._trackTop - self._parent._handleHeight/2) * self._parent._ratio);
	};
	
	this.stepDelay = 40;
	this.steps   = s?s:[0,25,50,70,85,95,97,99,100];
	this._values = [];
	this._parent = o;
	this._timer  = [];
	this._idle   = true;
	
	o.tweenTo = this._tweenTo;
	o.tweenBy = this._tweenBy;
	o.trackTween = this._trackTween;
	
	if (t) o._scrollTrack = function (e) {
		this.trackTween(e);
	};
};

function swapSteps (w) {
	scrollTween.steps = w;
}

function scrollbarEvent (o, type) {
	if (type == "mousedown") {
		if (o.className == "Scrollbar-Track") o.style.backgroundColor = "#E3E3E3";
		else o.style.backgroundColor = "#BBB";
	} else {
		if (o.className == "Scrollbar-Track") o.style.backgroundColor = "#EEE";
		else o.style.backgroundColor = "#CCC";
	}
}

function swapIt(o) {
	o.blur();
	if (o.className == "current") return false;
  
	var list = document.getElementById("Navigation").getElementsByTagName("a");
	for (var i = 0; i < list.length; i++) {
		if (list[i].className == "current") {
			list[i].className = "";
			document.getElementById(list[i].title).y = -scroller._y;
		}
		if (list[i].title == o.title) o.className = "current";
	}
  
	list = document.getElementById("Container").childNodes;
	for (var i = 0; i < list.length; i++) {
		if (list[i].tagName == "DIV") list[i].style.display = "none";
	}
  
	var top = document.getElementById(o.title);
	top.style.display = "block";
	scrollbar.swapContent(top);
	if (top.y) scrollbar.scrollTo(0, top.y);
  
	return false;
}
