function SequenceManager()
{
	this.locator = 0;
	this.sequence = new Array();
	this.callBack = callBack;
	this.play = play;
	
	function callBack()
	{
		if(this.locator+1<this.sequence.length)
		{
			this.locator += 1;
			this.sequence[this.locator].play();
		}
	}
	
	function play()
	{
		this.locator = 0;
		this.sequence[0].play();
	}
}

function FadeIn(target, manager, startOpacity, endOpacity, step, interval)
{	
	this.manager = manager;
	this.target = target;
	
	this.startOpacity = startOpacity;
	this.endOpacity = endOpacity;
	this.step = step;
	this.interval = interval;
	
	this.play = play;
	this.oneMoreStep = oneMoreStep;
	
	function play()
	{
		this.oneMoreStep(this.target, this.manager, this.startOpacity, this.endOpacity, this.step, this.interval);
	}
	
	function oneMoreStep(target, manager, startOpacity, endOpacity, step, interval)
	{
		target.style.opacity = startOpacity;
		target.style.filter = "alpha(opacity=" + startOpacity*100 + ")";
		setTimeout(function()
		{
			if(startOpacity + step < endOpacity)
			{
				oneMoreStep(target, manager, startOpacity+step, endOpacity, step, interval);
			}
			else
			{
				if(endOpacity==1)
				{
					target.style.filter = "none";
				}
				else
				{
					target.style.filter = "alpha(opacity=" + endOpacity*100 + ")";
				}
				target.style.opacity = endOpacity;
				manager.callBack();
			}
		}, interval);
	}
		
}

function Translation(target, manager, startTop, startLeft, endTop, endLeft, step, interval)
{
	this.play = play;
	this.oneMoreStep = oneMoreStep;
	
	var vecTop = (endTop-startTop);
	var vecLeft = (endLeft-startLeft);
	var norm = Math.sqrt(Math.pow(vecTop,2) + Math.pow(vecLeft,2));
	
	this.topInc = (vecTop*step)/norm;
	this.leftInc = (vecLeft*step)/norm;
	
	this.target = target;
	this.manager = manager;
	this.startTop = startTop;
	this.startLeft = startLeft;
	this.endTop = endTop;
	this.endLeft = endLeft;
	this.interval = interval;
	
	function play()
	{
		this.oneMoreStep(this.target, this.manager, this.startTop, this.startLeft, this.startTop, this.startLeft, this.endTop, this.endLeft,  this.topInc, this.leftInc, this.interval, 1);
	}
	
	function oneMoreStep(target, manager, currentTop, currentLeft, initTop, initLeft, endTop, endLeft, topInc, leftInc, interval, stepNumber)
	{
		target.style.top = addPx(currentTop);
		target.style.left = addPx(currentLeft);
		
		setTimeout(function()
		{
			topTest = true;
			leftTest = true;
			
			if(topInc != 0)
			{
				topTest = topInc*(removePx(target.style.top) + topInc) < endTop*topInc;
			}
			if(leftInc != 0)
			{
				leftTest = leftInc*(removePx(target.style.left) + leftInc) < endLeft*leftInc;
			}
			
			nextTop = Math.round(initTop+stepNumber*topInc);
			nextLeft = Math.round(initLeft+stepNumber*leftInc);
			
			if(topTest && leftTest)
			{	
				oneMoreStep(target, manager, nextTop, nextLeft,initTop, initLeft, endTop, endLeft, topInc, leftInc, interval,stepNumber+1);
			}
			else
			{
				target.style.top = addPx(endTop);
				target.style.left = addPx(endLeft);
				manager.callBack();
			}
		}, interval);
		
	}
	
	function addPx(value)
	{
		value += 'px';
		return value;
	}
	
	function removePx(value)
	{
		value = parseInt(value.replace('px', ''));
		return value;
	}
}

function ChangeSrc(img, newSrc, manager)
{
	this.play = play;
	this.img = img;
	this.newSrc = newSrc;
	this.manager = manager; 
	
	function play()
	{
		this.img.manager = this.manager;
		this.img.src = this.newSrc;
		if(this.img.complete)
		{
			this.manager.callBack();	
		}
		else
		{
			this.img.onload = function()
			{
				this.manager.callBack();
			};
		}
	}
}

function Wait(interval, manager)
{
	this.play = play;
	this.interval = interval;
	this.manager = manager;
	selfThis = this;
	
	function play()
	{
		setTimeout(function()
		{
			selfThis.manager.callBack();
			
		},this.interval);
	}
}
