var currentTab = 0;
var overrideAuto = false;

function showTab(number)
{
  var tab = document.getElementById("tab" + number);
  var lnk = document.getElementById("rotateTo" + number);

  if (tab && lnk)
  {
    if (tab.className.indexOf("show") > -1)
      return;

    tab.className += " show";

    if (lnk.className.indexOf("selected") > -1)
      return;

    lnk.className += " selected";
    
    currentTab = number;
  }
}
function hideTab(number)
{
  var tab = document.getElementById("tab" + number);
  var lnk = document.getElementById("rotateTo" + number);
  
  if (tab && lnk)
  {
    if (tab.className.indexOf("show") > -1)
      tab.className = tab.className.replace(" show", "");

    if (lnk.className.indexOf("selected") > -1)
      lnk.className = lnk.className.replace(" selected", "");
  }
}

function rotateRight(user)
{
  if (user)
    overrideAuto = true;

  if (currentTab < 3)
  {
    if (currentTab < -1)
      currentTab = -1;

    hideTab(currentTab);
    currentTab++;
    showTab(currentTab);
  }
  else
  {
    hideTab(3);
    currentTab = -1;
    rotateRight();
  }
}
function autoRotateRight()
{
  if (!overrideAuto)
  {
    rotateRight(false);
    setTimeout("autoRotateRight()", 5000);
  }
}

function rotateLeft()
{
  overrideAuto = true;
    
  if (currentTab > 0)
  {
    if (currentTab > 4)
      currentTab = 4;

    hideTab(currentTab);
    currentTab--;
    showTab(currentTab);
  }
  else
  {
    hideTab(0);
    currentTab = 4;
    rotateLeft();
  }
}

function rotateTo(number)
{
  overrideAuto = true;

  if (currentTab > -1 && currentTab < 4)
    hideTab(currentTab);
    
  showTab(number);
}

setTimeout("autoRotateRight()", 5000);
