function AnimateNextFrame(elementName, startingWidth, targetWidth, startingHeight, targetHeight, timeLength, currentFrame, sizeSuffix, functionToExecute)
{
    var msPerFrame = 1000 / 40;
    var frameCount = timeLength / msPerFrame;
    frameCount = RoundToDP(frameCount, 0);
    var element = document.getElementById(elementName);
            
    if (targetWidth > -1)
    {
        
        var widthDiff = targetWidth - startingWidth;
        if (widthDiff != 0)
        {
            if (currentFrame < frameCount)
            {
                var movementMultiplier = (CalculateSinPosition(currentFrame, frameCount));
                var newWidth = ((widthDiff / frameCount) * movementMultiplier) + startingWidth;
                newWidth = RoundToDP(newWidth, 0);
            }
            else
            {
                newWidth = targetWidth;
            }
            element.style.width = newWidth + sizeSuffix;  
        }
    }
    if (targetHeight > -1)
    {
        var heightDiff = targetHeight - startingHeight;
        
        if (heightDiff != 0)
        {
            if (currentFrame < frameCount)
            {
                var movementMultiplier = (CalculateSinPosition(currentFrame, frameCount));
                var newHeight = ((heightDiff / frameCount) * movementMultiplier) + startingHeight;
                newHeight = RoundToDP(newHeight, 0);
            }
            else
            {
                newHeight = targetHeight;
            }
            //var infoDiv = document.getElementById("infoDiv");
            //infoDiv.innerHTML = infoDiv.innerHTML + "<br /> old height: " + element.style.height + ", new height: " + newHeight;
            element.style.height = newHeight + sizeSuffix;              
        }

        
    }
    if (currentFrame < frameCount)
    {
        currentFrame++;
                
        var t = setTimeout("AnimateNextFrame(\"" + elementName + "\"," + startingWidth + "," + targetWidth + "," + startingHeight + "," + targetHeight + "," + timeLength + "," + currentFrame + ", \"" + sizeSuffix + "\", \"" + functionToExecute + "\")", msPerFrame);
    }
    else
    {
        if ((functionToExecute != null) && (functionToExecute != ""))
        {
            var t = setTimeout(functionToExecute, 1);
        }
    }
}



function RoundToDP(value, dp)
{
    dp = Math.pow(10,dp);
    value = Math.round((value*dp));
    value = (value / dp);
    return value;
}

function CalculateSinPosition(currentFrame, frameCount)
{
    currentFrameRelativeToPI = (((Math.PI) / frameCount) * currentFrame);
    currentFrameRelativeToPI = RoundToDP(currentFrameRelativeToPI - (Math.PI/2), 4);
    var sinePosition = (Math.sin(currentFrameRelativeToPI) + 1)/2;
    sinePosition = Math.pow(sinePosition, 1/4);
    return frameCount * RoundToDP(sinePosition, 2);
    
}