Scroller = function(idScrollPane, idContentPane, moveModifier, animationDelay, idPaneLogger)
{
	this.idPaneLogger = idPaneLogger;
	this.idScrollPane = idScrollPane;
	this.idContentPane = idContentPane;
	this.contentPaneXposition = this.getStyleNumericValue(this.idContentPane, "left");
	this.moveModifier = (moveModifier == null ? 0.2 : moveModifier);
	this.animationDelay = (animationDelay == null ? 35 : animationDelay);
	this.mouseOverPositionX = 0;
	this.isMouseOver = false;
	this.scrollPaneWidth = this.idScrollPane.width;
	this.timeOutRef = null;
	this.instance = null;
	this.lastDirection = 1;
	this.isAnimated = false;
	this.idleSpeed = 2;
	
	if (isNaN(this.scrollPaneWidth)) {
		this.scrollPaneWidth = this.idScrollPane.offsetWidth;
	}

	var attributes = { 
		left: { by: this.idleSpeed} 
	}; 
	

	this.contentItems = YAHOO.util.Dom.getChildren(idContentPane);
	this.contentItemsNumber = this.contentItems.length;
	this.contentItemWidth = this.contentItems[0].width;
	if (isNaN(this.contentItemWidth)) {
		this.contentItemWidth = this.contentItems[0].offsetWidth;
	}
	this.contentWidth = this.contentItemsNumber * this.contentItemWidth;
	this.contentFirstIndex = 0;
	this.contentLastIndex = this.contentItemsNumber - 1;
	YAHOO.util.Dom.setStyle(this.idContentPane, "left", ((this.contentItemWidth * -2) + 2) + "px" );
/*
	this.anim = new YAHOO.util.Anim(this.idContentPane, attributes, this.animationDelay);
	this.anim.onComplete.subscribe(function(a, b, c) {c.startScrolling();}, this);
	this.anim.animate();
	*/
	this.startScrolling();
	//var test = this;
	//Scroller.prototype.myTest = this;
//	this.timeOutRef = setInterval(this.startScrolling, 2000);
}

Scroller.prototype.startScrolling = function()
{
	var attributes;
	var move;
	//var contentPaneProjectedPosition;
	//alert(this.idPaneLogger);

	//alert(this.lastDirection);
	if(this.isMouseOver == true)
	{
		var mouseDistanceFromCenter = this.mouseOverPositionX - (this.scrollPaneWidth / 2);

		move = -Math.round( mouseDistanceFromCenter * this.moveModifier);

		if (move > 0 )
			this.lastDirection = 1;
		else if(move < 0)
			this.lastDirection = -1;
	}
	else
	{
		move = this.idleSpeed * this.lastDirection;
	}


/*
	this.anim.attributes = { 
		left: { by: move} 
	}; 
	*/
	
	//var contentPaneXposition = this.getStyleNumericValue(this.idContentPane, "left");
	//var mouseDistanceFromCenter = this.mouseOverPositionX - (this.scrollPaneWidth / 2);
	var contentPaneProjectedPosition;
	var firstItemPosition;
				
	contentPaneProjectedPosition = move + this.contentPaneXposition;
	
	// Deplace les items
	if (move < 0)
	{
		var boucle = true;
		while(boucle)
		{
			firstItemPosition = this.getStyleNumericValue(this.contentItems[this.contentFirstIndex], "left");
			if(firstItemPosition + contentPaneProjectedPosition < (-this.contentItemWidth * 2))
			{
				YAHOO.util.Dom.setStyle(this.contentItems[this.contentFirstIndex], "left", firstItemPosition + this.contentWidth + "px");
				this.contentFirstIndex++;
				this.contentLastIndex++;
				if(this.contentFirstIndex == this.contentItemsNumber) { this.contentFirstIndex = 0; }
				if(this.contentLastIndex == this.contentItemsNumber) { this.contentLastIndex = 0; }
			}
			else
			{
				boucle = false;
			}
		}
	}
	else if(move > 0)
	{
		var boucle = true;
		while(boucle)
		{
			firstItemPosition = this.getStyleNumericValue(this.contentItems[this.contentFirstIndex], "left");
			if(firstItemPosition + contentPaneProjectedPosition > 0)
			{
				YAHOO.util.Dom.setStyle(this.contentItems[this.contentLastIndex], "left", firstItemPosition - this.contentItemWidth + "px");
				
				this.contentFirstIndex--;
				this.contentLastIndex--;
				if(this.contentFirstIndex == -1) { this.contentFirstIndex = this.contentItemsNumber - 1; }
				if(this.contentLastIndex == -1) { this.contentLastIndex = this.contentItemsNumber - 1; }
			}
			else
			{
				boucle = false;
			}
		}
	}

	//if(contentPaneProjectedPosition != this.contentPaneXposition)
	//{
		this.contentPaneXposition = contentPaneProjectedPosition;
		YAHOO.util.Dom.setStyle(this.idContentPane, "left", this.contentPaneXposition + "px");
		YAHOO.lang.later(this.animationDelay, this, 'startScrolling');
	//}

//	this.logTo("animating");
	//this.anim.animate();
//	return this.isMouseOver;
}

Scroller.prototype.getStyleNumericValue = function(itemId, styleAttribute)
{
	var itemPosition = YAHOO.util.Dom.getStyle(itemId, styleAttribute);
	
	if(itemPosition.indexOf("px") != -1)
	{
		itemPosition = itemPosition.substring(0, itemPosition.indexOf("px"));
	}
	itemPosition = Number(itemPosition);
	return itemPosition;
}
/*
function proutProut(shmu)
{
	alert("");
	shmu.startScrolling();
}
var test = this;
*/
Scroller.prototype.mouseOverDetected = function()
{
	
//	this.logTo("mouseOverDetected");
	this.isMouseOver = true;
//	this.interval = setTimeout("function(test){test.startScrolling();}", 40, this);
	//YAHOO.lang.later(100, this, "startScrolling", null, true);
//	this.startScrolling();
}

Scroller.prototype.mouseOutDetected = function()
{
	this.isMouseOver = false;
//	this.logTo("mouseOutDetected");
//	clearInterval(this.interval);
}

Scroller.prototype.updateMouseOverPositionX = function(mouseX)
{
	this.mouseOverPositionX = mouseX;
}

Scroller.prototype.logTo = function(text)
{
	var p = document.createElement("span");
	p.innerHTML = text + "&nbsp; ";
	this.idPaneLogger.appendChild(p);
}
