﻿var currentPromo = 0;
var runClock = true;
var isFirstRun = true;
var t;
 function showItem(param, stopclock) {
     resetDots();
     currentPromo = param;     
     if(stopclock){
         clearInterval(t);
        }
     var promo = document.getElementById('promo');
    try {   
       if (window.XMLHttpRequest) {
            xhttp = new XMLHttpRequest();
        }
        else // Internet Explorer 5/6
        {
            xhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xhttp.open("GET", "/config/promowindow.xml", false);
        xhttp.send("");
        xmlDoc = xhttp.responseXML;
        document.getElementById('headline').innerHTML = '<a href="' + xmlDoc.getElementsByTagName('link')[param].childNodes[0].nodeValue + '">' + xmlDoc.getElementsByTagName('headline')[param].childNodes[0].nodeValue + '</a>';
        document.getElementById('strapline').innerHTML = '<a href="' + xmlDoc.getElementsByTagName('link')[param].childNodes[0].nodeValue + '">' + xmlDoc.getElementsByTagName('strapline')[param].childNodes[0].nodeValue + '</a>';
        document.getElementById('dot' + (param + 1)).style.color = '#FFFFFF';
        switch (param) { 
        case 0:
            promo.style.backgroundImage = 'url(/images-promo/one.jpg)';
            break;
        case 1:
            promo.style.backgroundImage = 'url(/images-promo/two.jpg)';
            break;
        case 2: 
            promo.style.backgroundImage = 'url(/images-promo/three.jpg)';
            break;
        }
    } catch (e) {

}
startTheClock();
}
function resetDots() {
    document.getElementById('dot1').style.color = '#666666';
    document.getElementById('dot2').style.color = '#666666';
    document.getElementById('dot3').style.color = '#666666';
}
function startTheClock() {
    if (isFirstRun) {
        isFirstRun = false;
        t = setInterval(autoChange, 10000);
       }
     
}
function autoChange() {
    if (currentPromo == 2) {
        currentPromo = 0
    } else {
        currentPromo = currentPromo + 1 ;
    }        
    showItem(currentPromo, false);          
}
window.onload = startTheClock

