// JavaScript Document
/*credits: Andrés Fernández, based in http://ajaxcookbook.org/transitions-animation-effects/ */
function Transition(curve, milliseconds, callback) {
		this.done_=false;
    	this.curve_ = curve;
    	this.milliseconds_ = milliseconds;
    	this.callback_ = callback;
    	this.start_ = new Date().getTime();
		this.run=function() {
			var _this=this;
   			if(!this.hasNext()) {
				window['globalIntervalo']=0;
				return;
			}
    		this.callback_(this.next());
			setTimeout(function(){_this.run.call(_this);}, 0);
		}
		this.hasNext=function() {
    		if(this.done_)
				return false;
    		var now = new Date().getTime();
    		if ((now - this.start_) > this.milliseconds_) {
       			this.done_ = true;
    		}
    		return true;
		}
		this.next=function() {
    		var now = new Date().getTime();
    		var percentage = Math.min(1, (now - this.start_) / this.milliseconds_);
			return this.curve_(percentage);
		}
}

function SineCurve(percentage) {
	return (1 - Math.cos(percentage * Math.PI)) / 2;
}

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