<!-- Begin JavaScript
/*
Attribution:
Original Code By Bret Taylor -- http://ajaxcookbook.org/
License Info: http://creativecommons.org/licenses/by/2.5/

Description:
Prototype to handle variable frame rate transitions in JavaScript.
Use with the included curve functions and an 'animation' callback
function to make the magic happen. ;')

Example:
//Move text diagonally across the screen...
var element = document.getElementById("animated");
element.style.position = "absolute";
element.style.left = "0px";
element.style.top = "0px";

//Pass the type of curve we want to use, how many milliseconds the animation
//should take, and an inline function which receives the percentage of 
//animation progress that can be used to determine the current point in the 
//element 'animation'.
var transition = new Transition(SineCurve, 1000, function(percentage) {
    var x = element.parentNode.offsetWidth - element.offsetWidth;
    var y = element.parentNode.offsetHeight - element.offsetHeight;
    element.style.left = Math.round(percentage * x) + "px";
    element.style.top = Math.round(percentage * y) + "px";
});
transition.run();
*/
function Transition(curve, milliseconds, callback) {
    this.curve_ = curve;
    this.milliseconds_ = milliseconds;
    this.callback_ = callback;
    this.start_ = new Date().getTime();
    var me = this;
    this.runCallback_ = function() {
        me.run();
    };
}

Transition.prototype.run = function() {
    if (!this.hasNext()) return;
    this.callback_(this.next());
    setTimeout(this.runCallback_, 10);
}

Transition.prototype.hasNext = function() {
    if (this.done_) return this.oneLeft_;
    var now = new Date().getTime();
    if ((now - this.start_) > this.milliseconds_) {
        this.done_ = true;
        this.oneLeft_ = true;
    }
    return true;
}

Transition.prototype.next = function() {
    this.oneLeft_ = false;
    var now = new Date().getTime();
    var percentage = Math.min(1, (now - this.start_) / this.milliseconds_);
    return this.curve_(percentage);

}

/*
Attribution:
Original Code By Bret Taylor -- http://ajaxcookbook.org/
License Info: http://creativecommons.org/licenses/by/2.5/

Description:
Generates a sine 'step value' based on the passed percentage.

Example:
var pos = SineCurve(50);

Special Notes:
Used by the transition prototype. May consider moving to the general utility classes later.
*/
function SineCurve(percentage) {
    return (1 - Math.cos(percentage * Math.PI)) / 2;
}

/*
Attribution:
Original Code By Bret Taylor -- http://ajaxcookbook.org/
License Info: http://creativecommons.org/licenses/by/2.5/

Description:
Returns a linear value. Basically the input gets output. 

Special Notes:
Used by the transition prototype. Will not be moved to general utilities as the 
//function is only useful within the context of the Transition prototype.

Example:
var pos = LinearCurve(50);
*/
function LinearCurve(percentage) {
    return percentage;
}
// End JavaScript -->