﻿// Freesat highlight rotation script

skdHighlight = function() {}
skdHighlight.prototype.delay = 10000; // time between highlights, in milliseconds
addLoadEvent(highlightInit);

function highlightInit()
{
  skdh = new skdHighlight();
  
  hContent = $('highlight');
  hImage = $('highlightImage');
  hLogo = $('highlightLogo');
  hProgramme = $('highlightProgramme');
  hTime = $('highlightTime');
  
  xmlFile = helper.importXml('./highlights/highlights.xml');
  xmlNodes = xmlFile.getElementsByTagName('highlight');
  currentNode = 0;
  
  setTimeout(function(){skdh.nextHighlight()}, skdh.delay);
} // highlightInit()

skdHighlight.prototype.nextHighlight = function()
{
  currentNode++;
  if(currentNode == xmlNodes.length) currentNode = 0;
  effect.fade(hContent, "fade: out, seconds: 0.3");
  setTimeout(function(){skdh.replaceContent()}, 500);
} // skdh.nextHighlight()

skdHighlight.prototype.replaceContent = function()
{
  hImage.src = "highlights/images/" + xmlNodes[currentNode].getAttribute("image");
  hLogo.src = "highlights/logos/" + xmlNodes[currentNode].getAttribute("logo");
  helper.clear(hProgramme);
  hProgramme.appendChild(document.createTextNode(xmlNodes[currentNode].getAttribute("programme")));
  helper.clear(hTime);
  hTime.appendChild(document.createTextNode(xmlNodes[currentNode].getAttribute("time")));
  setTimeout(function(){effect.fade(hContent, "seconds: 0.3")}, 500);
  setTimeout(function(){skdh.nextHighlight()}, (skdh.delay + 1000)); // add 1 second to the delay because of the fade time
} // skdh.replaceContent()