// JavaScript Document

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

addLoadEvent(TimeSwitch);
addLoadEvent(function() {
  /* more code to run on page load */
});

function ShiftTo(DivID) {
    Base = document.getElementById(DivID).parentNode;
    Sub = Base.getElementsByTagName('div');
    for (x = 0; x < Sub.length; x++) {
        if (Sub[x].parentNode == Base) {
            if (Sub[x].id == DivID) {
                Sub[x].style.display = "block";
            } else {
                Sub[x].style.display = "none";
            } 
        } 
    }
}
var cDivCount = 5;        //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 = 5000; //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
      if (document.getElementById('optSlide').checked)
         SlideDivOut();    //#1 - Slide current div out, then slide new div in
      else if (document.getElementById('optFade').checked)
         FadeDivOut();     //#2 - Fade current div out, then fade new div in
      else {               //#3 - No animation, just hide the current and show the new
         document.getElementById('tab' + vCurDiv).style.display = 'none';
         AdvanceDiv();
         document.getElementById('tab' + vCurDiv).style.display = 'block';
         TimeSwitch();    //Start timer to switch again in X seconds
      }
   }
}
function SlideDivOut() {
   if (vSeq < cSeqEnd) {
      vSeq++;
      document.getElementById('tab' + vCurDiv).style.left = (vSeq * cSlideIncrement) + 'px';
      setTimeout(SlideDivOut, cAnimateTime);
   }
   else {
      vSeq = 0;
      document.getElementById('tab' + vCurDiv).style.display = 'none';
      document.getElementById('tab' + vCurDiv).style.left = '0px';
      document.getElementById('tab' + vCurDiv).style.top = '0px';
      AdvanceDiv();
      document.getElementById('tab' + vCurDiv).style.left = (cDivWidth * -1) + 'px';
      document.getElementById('tab' + vCurDiv).style.display = 'block';
      setTimeout(SlideDivIn, cAnimateTime);
   }
}
function SlideDivIn() {
   if (vSeq < cSeqEnd) {
      vSeq++;
      document.getElementById('tab' + vCurDiv).style.left = ((cDivWidth * -1) + (vSeq * cSlideIncrement)) + 'px';
      setTimeout(SlideDivIn, cAnimateTime);
   }
   else {
      vSeq = 0;
      document.getElementById('tab' + 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('tab' + vCurDiv).style.opacity = vOpacity;
      document.getElementById('tab' + vCurDiv).style.filter = 'alpha(opacity=' + (vOpacity * 100) + ')';
      setTimeout(FadeDivOut, cAnimateTime);
   }
   else {
      vSeq = 0;
      document.getElementById('tab' + vCurDiv).style.display = 'none';
      document.getElementById('tab' + vCurDiv).style.opacity = 1;
      document.getElementById('tab' + vCurDiv).style.filter = 'alpha(opacity=100)';
      AdvanceDiv();
      document.getElementById('tab' + vCurDiv).style.opacity = 0;
      document.getElementById('tab' + vCurDiv).style.filter = 'alpha(opacity=0)';
      document.getElementById('tab' + vCurDiv).style.display = 'block';
      setTimeout(FadeDivIn, cAnimateTime);
   }
}
function FadeDivIn() {
   if (vSeq < cSeqEnd) {
      vSeq++;
      var vOpacity = vSeq * cFadeIncrement;
      document.getElementById('tab' + vCurDiv).style.opacity = vOpacity;
      document.getElementById('tab' + vCurDiv).style.filter = 'alpha(opacity=' + (vOpacity * 100) + ')';
      setTimeout(FadeDivIn, cAnimateTime);
   }
   else {
      vSeq = 0;
      document.getElementById('tab' + vCurDiv).style.opacity = 1;  //Just in case animation was a tad off
      document.getElementById('tab' + vCurDiv).style.filter = 'alpha(opacity=100)';
      TimeSwitch();    //Start timer to switch again in X seconds
   }
}
function AdvanceDiv() {
   if (vCurDiv == cDivCount)
      vCurDiv = 1;
   else
      vCurDiv++;
}
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

