function JSAnimator(container, source, nbFrames, manager)
{
	var selfThis = this;
	
	this.source = source;
	this.nbFrames = nbFrames;
	this.frames = new Array();
	this.imgBase = new Image();
	this.container = container;
	this.currentFrame = 0;
	this.playing = false;
	this.manager = manager;
	this.interval = 40;
	this.loop = false;
	
	this.loadIn = loadIn;
	this.play = play;
	this.stopIt = stopIt;
	this.oneMoreStep = oneMoreStep;
	this.gotoAndStop = gotoAndStop;
	
	this.loadIn();
	
	function loadIn()
	{	
		var temp = this.source.split(".");
		for(var i=0;i<nbFrames;i++)
		{
			this.frames[i] = new Image();
			this.frames[i].src = (temp[0] + addZero(i+1, 4) + "." + temp[1]);
		}
		this.imgBase.style.display = "none";
		this.container.appendChild(this.imgBase);
	}
	
	function addZero(nombre, nbChiffresSignif)
	{
		var temp = "";
		for(var i=nbChiffresSignif;i>0;i--)
		{
			if(nombre<Math.pow(10, (i-1)))
			{
				temp += "0";
			}
		}
		temp += nombre;
		return temp;
	}
	
	function play()
	{
		if(!this.playing)
		{
			this.playing = true;
			this.oneMoreStep();
		}
	}
	
	function stopIt()
	{
		if(this.playing)
		{
			this.playing = false;
		}
	}
	
	function gotoAndStop(location)
	{
		if(location == "previous")
		{
			if(this.currentFrame > 0)
			{
				this.currentFrame -= 1;
				this.playing = false;
				this.oneMoreStep();
			}
		}
		else if(location == "next")
		{
			if(this.currentFrame < this.frames.length)
			{
				this.currentFrame += 1;
				this.playing = false;
				this.oneMoreStep();
			}
		}
		else
		{
			if(location > 0 && location < this.frames.length)
			{
				this.currentFrame = location;
				this.playing = false;
				this.oneMoreStep();
			}
		}
	}
	
	function oneMoreStep()
	{
		this.imgBase.src = this.frames[this.currentFrame].src;
		if(this.imgBase.style.display == "none")
		{
			this.imgBase.style.display = "";
		}
		setTimeout(function()
		{
			if(selfThis.playing)
			{
				if(selfThis.currentFrame + 1 < selfThis.frames.length)
				{
					selfThis.currentFrame += 1;
					selfThis.oneMoreStep();
				}
				else
				{
					if(selfThis.loop)
					{
						selfThis.currentFrame = 0;
						selfThis.oneMoreStep();
					}
					else
					{
						selfThis.playing = false;
					}
					selfThis.manager.callBack();
				}
			}
		}, this.interval);
	}
}
