var easyAnimation = function(id){
	this.init.apply(this,arguments);
};

easyAnimation.prototype={
	_objs : null,
	_property : null,
	_start : null,
	_end : null,
	_sec : null,
	_resolution : 50,
	_timeHandler : null,
	_direction : 1,
	_endCall : null,
	_rewindEndCall : null,
	_i : null,
	init:function(obj, property, start, end, sec, curve, endCall, rewindEndCall){
		if(!isArray(obj))	this._objs = new Array(obj);
		else				this._objs = obj;
		this._property		= property;
		this._start			= parseFloat(start);
		this._end			= parseFloat(end);
		this._sec			= (sec				!== undefined)?sec				:0.25;
		this._curve			= (curve			!== undefined)?curve			:2;
		this._endCall		= (endCall			!== undefined)?endCall			:null;
		this._rewindEndCall	= (rewindEndCall	!== undefined)?rewindEndCall	:null;
	},
	start:function(i){
		clearTimeout(this._timeHandler);
		this._i			= (i)?i*1000:0;
		this._direction	= 1;
		this.animation();
	},
	stop:function(){
		clearTimeout(this._timeHandler);
		return this._i * 0.001;
	},
	rewind:function(i){
		clearTimeout(this._timeHandler);
		this._i			= (i)?i*1000:this._i;
		this._direction	= -1;
		this.animation();
	},
	animation:function(){
		this._i += 1000 * (this._resolution / (this._sec * 1000)) * this._direction;
		var val = this._start + (this._end - this._start) * curve2(this._i/1000, this._curve);
		if(this._direction >= 1 && this._i <= 1000
		|| this._direction <= -1 && this._i >= 0){
			this.setProperty(this._objs, this._property, val);
			this._timeHandler = setTimeout(this.bind(this.animation), this._resolution);
		} else{
			if(this._direction >= 1){
				this.setProperty(this._objs, this._property, this._end);
				if(this._endCall) this._endCall.apply();
			} else{
				this.setProperty(this._objs, this._property, this._start);
				if(this._rewindEndCall) this._rewindEndCall.apply();
			}		
		}
	},
	setProperty:function(objs, property, value){
		switch(property){
			case "opacity":
				for(var i=0; i<objs.length; i++){
					setOpacity(objs[i], value);
				}
			break;
			default:
				for(var i=0; i<objs.length; i++){
					objs[i].style[property] = value + "px";
				}
			break;
		}
	},
	bind:function(method,arg){
		var _this=this;var _arg=(arg)?arg:[];
		return function(){
			method.apply(_this,_arg);
		}
	}
};

