
var maxPanels = panels.length;
var currentPanel = 0;

// preloads the images
function loadPanels()
{

 for(i=0; i<maxPanels; i++)
 {
   var img = new Image();
   img.src = "../images/splashes/" + panels[i][0];
 }
 startCycle();
}

function startCycle()
{
  panelCycleID = window.setInterval(cyclePanel, 5000);
}

function endCycle()
{
  window.clearInterval(panelCycleID);
}

// gets called to move to the next panel
function cyclePanel()
{
  if (currentPanel >= maxPanels)
  {
    currentPanel = 0;
  }
  setPanel();
  currentPanel++;
}

function nextPanel()
{
  currentPanel++;
  if (currentPanel >= maxPanels)
  {
    currentPanel = 0;
  }
  setPanel();
}

function previousPanel()
{
  currentPanel--;
  if (currentPanel < 0)
  {
    currentPanel = maxPanels - 1;
  }
  setPanel();
}

//
function setPanel()
{
  var panelImage = document.getElementById("panel-image");
  panelImage.setAttribute("src", "../images/splashes/" + panels[currentPanel][0]);
  var panelLink = document.getElementById("panel-href");
  var link = panels[currentPanel][1];
  if (link.indexOf('http')==0)
  {
    panelLink.setAttribute("href", panels[currentPanel][1]);
  }
  else
  {
    panelLink.setAttribute("href", "../" + panels[currentPanel][1]);
  }
}

loadPanels();

