var AnimationManager=new function(){
	var TimerID;
	var Config={
		Container:		null,
		Property:		null,
		StepQt:			20,
		StepTime:		20,
		ObjectQt:		1,
		ObjectTime:		0,
		ObjectSampling:	-0
	}
	var Steps=new Array();
	var CurrentIndex=0;
	
	var Validate=function(){
		if(!Config.Container){
			return false;
		}
		if(typeof Config.Container.style[Config.Property]=='undefined'){
			return false;
		}
		return true;
	}
	
	this.SetConfig=function(NewConfig){
		for(var Key in NewConfig){
			switch(typeof Config[Key]){
				case 'undefined':
					break;
				case 'int':
					Config[Key]=parseInt(NewConfig[Key]);
					break;
				default:
					Config[Key]=NewConfig[Key];
					break;
			}
		}
	}
	
	this.Next=function(){
		return this.Change(CurrentIndex+1);
	}
	
	this.Previous=function(){
		return this.Change(CurrentIndex-1);
	}

	this.Change=function(Index){
		if(!Validate())return false;
		clearTimeout(TimerID);
		
		Index=Math.abs(parseInt(Index)%Config.ObjectQt);
		CurrentIndex=Index;
		
		Start=Config.Container.style[Config.Property];
		Start=(Start==undefined || !Start)?0:Start;
		Start=parseInt(Start);
		Finish=Index*Config.ObjectSampling;
		for(var i=0;i<Config.StepQt;i++){
			Steps[i]=Finish-(Finish-Start)*(0.5*(1+Math.cos(Math.PI*(i+1)/Config.StepQt)));
		}
		this.Animate(0);
		return false;
	}
	
	this.Animate=function(i){
		if(!Validate())return;
		i=Math.abs(parseInt(i));
		if(i==Steps.length && Config.ObjectTime){
			TimerID=setTimeout('AnimationManager.Change('+(CurrentIndex+1)+')',Config.ObjectTime);
		}
		if(i>Steps.length-1)
			return;
		Config.Container.style[Config.Property]=Steps[i]+'px';
		TimerID=setTimeout('AnimationManager.Animate('+(i+1)+')',Config.StepTime);
	}
	
	this.OnLoad=function(){
		if(Config.ObjectTime)
			TimerID=setTimeout('AnimationManager.Change('+(CurrentIndex+1)+')',Config.ObjectTime);
	}
}
