/**
 * @author jk
 */
function transicion(curva,ms,callback,end,endcallback){
    this.ant=0.01;
    this.done_=false;
    var _this=this;
    this.start=new Date().getTime();
    this.init=function(){
        setTimeout(function(){
                if(!_this.next()){
                    callback(1);
                    _this.done_=true;
                    window.globalIntervalo=0;
                    return;
                }
                callback(_this.next());
                _this.init();
            },13);
    }
    this.next=function(){
        var now=new Date().getTime();
        if ((now - this.start) > ms) {
endcallback;
			if (end) {
				end();
			}
			return false;
		}
        return this.ant=curva((now-this.start+.001)/ms,this.ant);
    }
}

function linear(p,ant){
    var maxValue=1, minValue=.001, totalP=1, k=1;
    var delta = maxValue - minValue; 
    var stepp = minValue+(Math.pow(((1 / totalP) * p), k) * delta); 
    return stepp; 
}
function senoidal(p,ant){
    return (1 - Math.cos(p * Math.PI)) / 2;
}

function desacelerado(p,ant){
    var maxValue=1, minValue=.001, totalP=1, k=.45;
    var delta = maxValue - minValue; 
    var stepp = minValue+(Math.pow(((1 / totalP) * p), k) * delta); 
    return stepp; 
}

function acelerado(p,ant){
    var maxValue=1, minValue=.001, totalP=1, k=7;
    var delta = maxValue - minValue; 
    var stepp = minValue+(Math.pow(((1 / totalP) * p), k) * delta); 
    return stepp; 
}

function rebote(p,ant){
    if(p<=0.6){
        return Math.pow(p*5/3,2);}
    else{
        return Math.pow((p-0.8)*5,2)*0.4+0.6;
    }
}


function fx(obj,efectos,ms,cola,curva,endcallback){
    if(!window.globalIntervalo)
        window.globalIntervalo=1;
    else {
        if(cola)
            return setTimeout(function(){fx(obj,efectos,ms,cola,curva)},30);
        else
            return;
    }    
    var t=new transicion(
    curva,ms,function(p){
        for (var i=0;efectos[i];i++){
            if(efectos[i].fin<efectos[i].inicio){
                var delta=efectos[i].inicio-efectos[i].fin;
                obj.style[efectos[i].propCSS]=(efectos[i].inicio-(p*delta))+efectos[i].u;
               if(efectos[i].propCSS=='opacity'){
                	if(efectos[i].inicio-(p*delta)==efectos[i].fin){
                		obj.style.display="none";
                	}
                    obj.style.zoom=1;
                    obj.style.MozOpacity = (efectos[i].inicio-(p*delta));
                    obj.style.KhtmlOpacity = (efectos[i].inicio-(p*delta));
                    obj.style.filter='alpha(opacity='+100*(efectos[i].inicio-(p*delta))+')';
                }
            }
            else{
                var delta=efectos[i].fin-efectos[i].inicio;
                obj.style[efectos[i].propCSS]=(efectos[i].inicio+(p*delta))+efectos[i].u;
                if(efectos[i].propCSS=='opacity'){
                	if(efectos[i].inicio==0){
                		obj.style.display="block";
                	}
                    obj.style.zoom=1;
                    obj.style.MozOpacity = (efectos[i].inicio+(p*delta));
                    obj.style.KhtmlOpacity = (efectos[i].inicio+(p*delta));
                    obj.style.filter='alpha(opacity='+100*(efectos[i].inicio+(p*delta))+')';
                }
            }
        }
        
    },endcallback);
    t.init();
    t=null;
} 

