function Scroller()
{
	this.Init = function(sScrollContainerId, sScrollingItemId, bVertical, iScrollingStep,bContinuous)
	{
		
		// Attributs du composant
		this.oScrollContainer = $(sScrollContainerId);                 // container fenêtre de défilement (div)
		this.oScrollingItem = $(sScrollingItemId);                     // zone de contenu défilant (div ou ul)
		this.bVertical = bVertical;                                    // défilement horizontal ou vertical ?
		this.iScrollingStep = (iScrollingStep ? iScrollingStep : 25);  // pas de défilement (en px)
		this.iScrollContainerSize = 0;                                 // largeur/hauteur de la fenêtre de défilement (en px)
		this.iScrollingItemSize = 0;                                   // largeur/hauteur de la zone de contenu défilant (en px)
		this.iStartPositionOffset = 0;                                 // décalage de la position initiale de la zone défilante (en px)
		this.iEndPositionOffset = 0;                                   // décalage de la position finale de la zone défilante (en px)
		this.iDuration = 0.1 * this.iScrollingStep / 100;
		this.bContinuous = bContinuous;									//est ce que l'animation doit être circulaire? NE PEUX FONCTIONNER QU'AVEC LE PREMIER ELEMENT DUPLIQUE!
		
		if (this.bVertical) {
			this.iScrollContainerSize = Math.floor(this.oScrollContainer.getStyle('height').split('px')[0]);
			this.iScrollingItemSize = Math.floor(this.oScrollingItem.getStyle('height').split('px')[0]);
		}
		else {
			this.iScrollContainerSize = Math.floor(this.oScrollContainer.getStyle('width').split('px')[0]);
			this.iScrollingItemSize = Math.floor(this.oScrollingItem.getStyle('width').split('px')[0]);
		}
	}

	this.SetPadding = function(paddingLeft, paddingRight)
	{
		this.iStartPositionOffset  = paddingLeft;
		this.iEndPositionOffset = paddingRight;
	}
	
	// Renvoie une représentation de l'élément sous forme de chaine
	this.ToString = function()
	{
		var s = '[sScrollContainerId=' + this.oScrollContainer.id + '; ';
		s += 'sScrollingItemId=' + this.oScrollingItem.id + '; ';
		s += 'bVertical=' + this.bVertical + '; ';
		s += 'iScrollingStep=' + this.iScrollingStep + '; ';
		s += 'iScrollContainerSize=' + this.iScrollContainerSize + '; ';
		s += 'iScrollingItemSize=' + this.iScrollingItemSize + '; ';
		s += 'iStartPositionOffset =' + this.iStartPositionOffset  + '; ';
		s += 'iEndPositionOffset=' + this.iEndPositionOffset + ']';
		return s;
	}

	this.Move = function(iScrollingStep)
	{
		if (this.bVertical) {
			new Effect.Move(this.oScrollingItem, { y: iScrollingStep, 
												duration: this.iDuration,
												transition: Effect.Transitions.linear,
												queue: { position: 'end', scope: 'global', limit: 1 }
												}
			);
		} else {
			new Effect.Move(this.oScrollingItem, { x: iScrollingStep, 
												duration: this.iDuration, 
												transition: Effect.Transitions.linear,
												queue: { position: 'end', scope: 'global', limit: 1 }
												}
			);
		}
	}

	
	//Permet de se déplacer de l element X à l'element Y
	this.GoToPosition = function(iPosition)
	{
		//on récupère la possition actuelle
		var iCurrentPosition = Math.round(Math.abs(this.oScrollingItem.positionedOffset().left / this.iScrollingStep));
		if (this.bContinuous && iCurrentPosition==(this.iScrollingItemSize / this.iScrollingStep)-1){
				//Si on est en continue, la première actu est en double donc la position 0 et N sont confondus
				//On retourne à la position 0 avant de faire le mouvement
				this.oScrollingItem.style.left='0px';
				iCurrentPosition = 0;
		}
		this.Move((Math.abs(iCurrentPosition) - iPosition) * this.iScrollingStep);
	}

	this.GoForward = function()
	{
		if (this.iScrollingItemSize + this.GetPositionedOffset() > this.iScrollContainerSize + this.iEndPositionOffset) {
			this.Move(- this.iScrollingStep);
		} else {
			if (this.bContinuous){
				//Si on est en continue, on a 2 fois la première news en position 0 et N, on retourne à la position 0 puis on bonge à la position 1 pour faire l'effet continue
				if (this.bVertical) {
					this.oScrollingItem.style.top='0px';
				} else {
					this.oScrollingItem.style.left='0px';
				}
				this.Move(- this.iScrollingStep);
			}
		}
	}

	this.GetPositionedOffset = function()
	{
		if (this.bVertical){
			return this.oScrollingItem.positionedOffset().top;
		} else {
			return this.oScrollingItem.positionedOffset().left;
		}
	}

	this.GoBack = function()
	{
		if (this.GetPositionedOffset() < - this.iStartPositionOffset ) {
			this.Move(this.iScrollingStep);
		} else {
			if (this.bContinuous){
				//Si on est en continue, on va à la dernière position avant de se décaler à l'avant dernière position
				if (this.bVertical) {
					this.oScrollingItem.style.top = (-this.iScrollingItemSize + this.iScrollingStep) + 'px';
				} else {
					this.oScrollingItem.style.left = (-this.iScrollingItemSize + this.iScrollingStep) + 'px';
				}
				this.Move(this.iScrollingStep);
			}
		}
	}

}

