﻿var screenWidth = $(window).width();
var screenHeight = $(window).height();
var defaultEasing = "linear";

function move(theIndex, TheAnimationSequence, objectToAnimate, Loop, LoopTime) {
    if (theIndex < TheAnimationSequence.length) {
        var anim = {};
        var theEasing = defaultEasing;
        var theParams = TheAnimationSequence[theIndex].split(",")
        for (i = 0; i < theParams.length - 1; i++) {
            execParamaters = theParams[i].split(":");

            anim[execParamaters[0]] = execParamaters[1];
            if (execParamaters.length > 2) {
                if (execParamaters[2] != "") {
                    theEasing = execParamaters[2];
                }
                if (execParamaters.length == 5) {
                    setTimeout(execParamaters[3], execParamaters[4]);
                }
                else {
                    if (execParamaters.length == 4) {
                        eval(execParamaters[4]);
                    }
                }
            }
        }

        // grab the last index of the array to get the time to execute the animation
        var theTime = theParams[theParams.length - 1];
        $(objectToAnimate).animate(anim, parseInt(theTime), theEasing, function () {
            move(theIndex + 1, TheAnimationSequence, objectToAnimate, Loop, LoopTime);
        });
    }
    else {
        if (Loop) {
            move(0, TheAnimationSequence, objectToAnimate, Loop, LoopTime);
        }
    }
}

function doStop(theObject) {
    $(theObject).stop();
}

