var cDivCount = 4;        //Keep track of number of divs to rotate
var cDivWidth = 350;      //Keep track of div width
var cSeqEnd = 20;         //Keep track of number of steps in animation
var cTimeToSwitch = 3000; //Keep track of milliseconds before switching to next div
var cAnimateTime = 50;    //Keep track of milliseconds between steps in animation
var cSlideIncrement = cDivWidth / cSeqEnd;
var cFadeIncrement = 1 / cSeqEnd;
 
var vDoSwitch = false;
var vCurDiv = 1;
var vSeq = 0;
 
function TimeSwitch() {
   vDoSwitch = true;                      //Tell program to proceed with switch
   setTimeout(SwitchDiv, cTimeToSwitch);  //Activate switch after X seconds
}
function StopSwitch() {
   vDoSwitch = false;     //Tell program to cancel switch
}
function SwitchDiv() {
   if (vDoSwitch) {        //If switch is set to go, then choose switch type

    FadeDivOut();     //#2 - Fade current div out, then fade new div in
 
   }
}
function SlideDivOut() {
   if (vSeq < cSeqEnd) {
      vSeq++;
      document.getElementById('div' + vCurDiv).style.left = (vSeq * cSlideIncrement) + 'px';
      setTimeout(SlideDivOut, cAnimateTime);
   }
   else {
      vSeq = 0;
      document.getElementById('div' + vCurDiv).style.display = 'none';
      document.getElementById('div' + vCurDiv).style.left = '0px';
      document.getElementById('div' + vCurDiv).style.top = '0px';
      AdvanceDiv();
      document.getElementById('div' + vCurDiv).style.left = (cDivWidth * -1) + 'px';
      document.getElementById('div' + vCurDiv).style.display = 'block';
      setTimeout(SlideDivIn, cAnimateTime);
   }
}
function SlideDivIn() {
   if (vSeq < cSeqEnd) {
      vSeq++;
      document.getElementById('div' + vCurDiv).style.left = ((cDivWidth * -1) + (vSeq * cSlideIncrement)) + 'px';
      setTimeout(SlideDivIn, cAnimateTime);
   }
   else {
      vSeq = 0;
      document.getElementById('div' + vCurDiv).style.left = '0px';  //Just in case animation was a tad off
      TimeSwitch();    //Start timer to switch again in X seconds
   }
}
function FadeDivOut() {
   if (vSeq < cSeqEnd) {
      vSeq++;
      var vOpacity = 1 - (vSeq * cFadeIncrement);
      document.getElementById('div' + vCurDiv).style.opacity = vOpacity;
      document.getElementById('div' + vCurDiv).style.filter = 'alpha(opacity=' + (vOpacity * 100) + ')';
      setTimeout(FadeDivOut, cAnimateTime);
   }
   else {
      vSeq = 0;
      document.getElementById('div' + vCurDiv).style.display = 'none';
      document.getElementById('div' + vCurDiv).style.opacity = 1;
      document.getElementById('div' + vCurDiv).style.filter = 'alpha(opacity=100)';
      AdvanceDiv();
      document.getElementById('div' + vCurDiv).style.opacity = 0;
      document.getElementById('div' + vCurDiv).style.filter = 'alpha(opacity=0)';
      document.getElementById('div' + vCurDiv).style.display = 'block';
      setTimeout(FadeDivIn, cAnimateTime);
   }
}
function FadeDivIn() {
   if (vSeq < cSeqEnd) {
      vSeq++;
      var vOpacity = vSeq * cFadeIncrement;
      document.getElementById('div' + vCurDiv).style.opacity = vOpacity;
      document.getElementById('div' + vCurDiv).style.filter = 'alpha(opacity=' + (vOpacity * 100) + ')';
      setTimeout(FadeDivIn, cAnimateTime);
   }
   else {
      vSeq = 0;
      document.getElementById('div' + vCurDiv).style.opacity = 1;  //Just in case animation was a tad off
      document.getElementById('div' + vCurDiv).style.filter = 'alpha(opacity=100)';
      TimeSwitch();    //Start timer to switch again in X seconds
   }
}
function AdvanceDiv() {
   if (vCurDiv == cDivCount)
      vCurDiv = 1;
   else
      vCurDiv++;
}
