function animate(animation, elementImgId) {
  advanceAnimation(animation, elementImgId);
  setTimeout(function() {animate(animation, elementImgId);}, animation.delay);
}
function advanceAnimation(animation, elementImgId) {
  var animFrameImg = document.getElementById(elementImgId);
  animFrameImg.src = animation.images[animation.imgNumber].src;
  if (animation.isPlaying)
  {
    ++animation.imgNumber;
    if (animation.imgNumber >= animation.imgEndNumber)
      animation.imgNumber = animation.imgFirstNumber;
  }
}
function rewind(animation, elementButtonId) {
  var button = document.getElementById(elementButtonId);
  button.src = "../images/sequence-begin-pressed.png";
  animation.imgNumber = animation.imgFirstNumber;
  setTimeout("document.getElementById(\""+elementButtonId+"\").src = \"../images/sequence-begin-enabled.png\"", 100);
}
function wind(animation, elementButtonId) {
  var button = document.getElementById(elementButtonId);
  button.src = "../images/sequence-end-pressed.png";
  animation.imgNumber = animation.imgEndNumber-1;
  setTimeout("document.getElementById(\""+elementButtonId+"\").src = \"../images/sequence-end-enabled.png\"", 100);
}
function backward(animation, elementButtonId) {
  var button = document.getElementById(elementButtonId);
  button.src = "../images/sequence-backward-pressed.png";
  --animation.imgNumber;
  if (animation.imgNumber < animation.imgFirstNumber)
    animation.imgNumber = animation.imgEndNumber-1;
  setTimeout("document.getElementById(\""+elementButtonId+"\").src = \"../images/sequence-backward-enabled.png\"", 100);
}
function forward(animation, elementButtonId) {
  var button = document.getElementById(elementButtonId);
  button.src = "../images/sequence-forward-pressed.png";
  ++animation.imgNumber;
  if (animation.imgNumber >= animation.imgEndNumber)
    animation.imgNumber = animation.imgFirstNumber;
  setTimeout("document.getElementById(\""+elementButtonId+"\").src = \"../images/sequence-forward-enabled.png\"", 100);
}
function switchPlayPause(animation, elementButtonId) {
  animation.isPlaying = !animation.isPlaying;
  var button = document.getElementById(elementButtonId);
  button.src = animation.isPlaying ? "../images/sequence-pause-enabled.png" : "../images/sequence-play-enabled.png";
}

