function Carroussel(_name,_container,_containerInner,_btnCarrousselLeft,_btnCarrousselRight){
	this.debug = "";
	this.name = _name;
	this.container = document.getElementById(_container);
	this.containerInner = document.getElementById(_containerInner);
	this.keyTag = "li";
	this.btnCarrousselLeft = document.getElementById(_btnCarrousselLeft);
	this.btnCarrousselRight = document.getElementById(_btnCarrousselRight);
	this.sourcesWidth = new Array();
	this.init = fillCarroussel;
	this.slideLeft = slideLeft;
	this.slideRight = slideRight;
	this.setCssPos = setCssPos;
	this.animSlideLeft = animSlideLeft;
	this.animSlideRight = animSlideRight;
	this.getStopIndex = getStopIndex;
	this.animStop = animStop;
	this.processId = null;
	this.counter = 0;
	this.currentIndexSource = 0;
	this.interval = 1;
	this.screw = 8;
	this.screw_orig = 0;
	this.sourcesOffsetWidth = 0;
	this.pos = 0;
	this.maxLeft = false;
	this.maxRight = true;
	this.getElementsWidth = getElementsWidth;
	this.sourcesLoaded = false;
	this.setClass = setClass;
	this.getNearestMultiple = getNearestMultiple;
	this.getNearestMultipleUp = getNearestMultipleUp;
}
function fillCarroussel(){
	this.setClass(this.btnCarrousselLeft,"inactive");
	this.screw_orig = this.screw;
}
function getElementsWidth(){
		if(! this.sourcesLoaded){
			var elements = this.containerInner.getElementsByTagName(this.keyTag);
			for(var i = 0,l=elements.length;i<l;i++){
				this.sourcesOffsetWidth = this.sourcesOffsetWidth + elements[i].offsetWidth;
				this.sourcesWidth.push(elements[i].offsetWidth);
			}
			this.sourcesLoaded = true;
		}
}
function slideLeft(){
	if(this.maxLeft){ }
	else{
		this.setClass(this.btnCarrousselLeft,"");
		this.animStop();
		this.getElementsWidth();
		this.maxRight = false;
		this.animSlideLeft();
		this.getStopIndex();
	}
}
function animSlideLeft(){
	this.debug += " | "+this.counter;
	this.setCssPos(this.containerInner,"left",this.counter);
	this.counter = this.counter - this.screw ;
	this.processId = setTimeout(this.name + '.startLeft()', this.interval);
	if(this.screw > 1){
		var nearestMultiple = this.getNearestMultiple(this.screw,this.pos - this.sourcesWidth[this.currentIndexSource] - 1);
		if((this.counter < nearestMultiple - (nearestMultiple * 2))){
			this.counter = this.counter + this.screw;
			this.screw = 1;
		}
	}
	if(this.counter == this.pos - this.sourcesWidth[this.currentIndexSource] - 1){
		this.animStop();
		this.pos = this.pos - this.sourcesWidth[this.currentIndexSource];
		if(this.currentIndexSource < this.sourcesWidth.length - 1)
			this.currentIndexSource = this.currentIndexSource + 1;
		if(this.currentIndexSource == this.getStopIndex()){
			this.maxLeft = true;
			this.setClass(this.btnCarrousselRight,"inactive");
			this.setClass(this.btnCarrousselLeft,"");
		}
		this.screw = this.screw_orig;
	}
}
function slideRight(){
	if(this.maxRight){ }
	else{
		this.btnCarrousselRight.className = "";
		this.animStop();
		this.getElementsWidth();
		this.maxLeft = false;
		this.animSlideRight();
	}
}
function animSlideRight(){
	this.processId = setTimeout(this.name + '.startRight()', this.interval);
	this.setCssPos(this.containerInner,"left",this.counter);
	this.counter = this.counter + this.screw ;
	if(this.screw > 1){
		var nearestMultipleUp = this.getNearestMultipleUp(this.screw,this.pos + this.sourcesWidth[this.currentIndexSource-1] + 1);
		if((this.counter > nearestMultipleUp - (nearestMultipleUp * 2))){
			this.counter = this.counter - this.screw;
			this.screw = 1;
		}
	}
	if(this.counter == this.pos + this.sourcesWidth[this.currentIndexSource-1] + 1){
		this.animStop();
		this.pos = this.pos + this.sourcesWidth[this.currentIndexSource-1];
		if(this.currentIndexSource != 0)
			this.currentIndexSource = this.currentIndexSource - 1;
		if(this.currentIndexSource == 0){
			this.maxRight = true;
			this.setClass(this.btnCarrousselRight,"");
			this.setClass(this.btnCarrousselLeft,"inactive");
		}
		this.screw = this.screw_orig;
	}
}
function getStopIndex(){
	var cumul = 0;
	var indexStop = 0;
	for(l=this.sourcesWidth.length-1,i = l;i>=0;i--){
		cumul = cumul + this.sourcesWidth[i];
		if(cumul > this.container.offsetWidth){
			indexStop = i;
			i = -1;
		}
	}
	return indexStop + 1;
}
function setCssPos(obj,attr,posInt){ obj.style[attr] = posInt+ "px"; }
function animStop()
{
  if (this.processId) clearTimeout(this.processId);
  this.processId = null;
}
function setClass(obj,className){obj.className=className;}
function getNearestMultiple(num1, num2){
	num1 = Math.abs(num1); num2 = Math.abs(num2);
	var cum = 0;
	var res = 0;
	for(var i = num1;i<1000;i++){
		if((cum + num1)>num2){
			(cum == num2)?res = cum-num1:res = cum;
			i = 1001;
		}
		else
			cum = cum + num1;
	}
	return res;
}
function getNearestMultipleUp(num1, num2){
	num1 = Math.abs(num1); num2 = Math.abs(num2);
	var cum = 0; var res = 0;
	for(var i = 1;i<1000;i++){
		if((cum + num1)>num2){
			res = cum+num1;
			i = 1001;
		}
		else
			cum = cum + num1;
	}
	return res;
}
Carroussel.prototype.startLeft = animSlideLeft;
Carroussel.prototype.startRight = animSlideRight;