var Carrousel = function()
{
	this.oContainer = null;
	this.oPrevButton = null;
	this.oNextButton = null;
	this.oGalleryList = null;
	this.aItems = [];
	this.nWidthItem = 0;
	this.nWidthGallery = 0;
	this.nWidth = 0;
	this.nHeight = 0;
};
Carrousel.prototype.setContainer = function(oContainer)
{
	this.oContainer = oContainer;
	return this;
};
Carrousel.prototype.setPrevButton = function(oPrevButton)
{
	this.oPrevButton = oPrevButton;
	return this;
};
Carrousel.prototype.setNextButton = function(oNextButton)
{
	this.oNextButton = oNextButton;
	return this;
};
Carrousel.prototype.setWidth = function(nWidth)
{
	this.nWidth = nWidth;
	return this;
};
Carrousel.prototype.setWidthItem = function(nWidthItem)
{
	this.nWidthItem = nWidthItem;
	return this;
};
Carrousel.prototype._setGalleryList = function()
{
	this.oGalleryList = $("ul",this.oContainer).get(0);
	this.aItems = $("li",this.oGalleryList);	
	var self = this;
	this.aItems.each(function()
	{
		self.nWidthGallery+= parseInt($(this).outerWidth(),10);
	});
};
Carrousel.prototype._getLeftPosition = function()
{
	return parseInt($(this.oGalleryList).css("left"),10);
};
Carrousel.prototype._addBehaviourPrevButton = function()
{
	var self = this;
	$(this.oPrevButton).click(function()
	{
		var nPosLeft = self._getLeftPosition();
		var nNewPosLeft = (nPosLeft + self.nWidthItem);
		
		if(nPosLeft < 0)
		{
			self.oGalleryList.style.left = nNewPosLeft+"px";
		}
		return false;
	});
};
Carrousel.prototype._addBehaviourNextButton = function()
{
	var self = this;
	$(this.oNextButton).click(function()
	{
		var nPosLeft = self._getLeftPosition();
		var nOuterWidthUL = self.nWidthGallery;
		var nNewPosLeft = (nPosLeft - self.nWidthItem);
		
		if(nNewPosLeft >= ((nOuterWidthUL-self.nWidth)*-1))
		{
			self.oGalleryList.style.left = nNewPosLeft+"px";
		}
		return false;
	});
};
Carrousel.prototype.applyBehaviour = function()
{
	this._setGalleryList();
	this._addBehaviourPrevButton();
	this._addBehaviourNextButton();
};
