var count = 1;
var pid = null;
var delay = 3000;
var des = null;

function selectAD(index) {
    if (pid != null) clearInterval(pid);
    var obj = null;
    var addes = document.getElementById("addes");
    for (var i = 1; i < 5; i++) {
        obj = document.getElementById("adimg" + i);
        obj.style.display = "none";
        btn = document.getElementById("btnad" + i);
        btn.style.backgroundColor = "";
    }
    obj = document.getElementById("adimg" + index);
    obj.style.display = "block";
    btn = document.getElementById("btnad" + index);
    btn.style.backgroundColor = "Gray";
    count = index + 1;
    if (count > 4) count = 1;
    pid = setInterval(autoSelect, delay);
}

function autoSelect() {
    if (pid != null) clearInterval(pid);
    var obj = null;
    var btn = null;
    for (var i = 1; i < 5; i++) {
        obj = document.getElementById("adimg" + i);
        obj.style.display = "none";
        btn = document.getElementById("btnad" + i);
        btn.style.backgroundColor = "";
    }
    obj = document.getElementById("adimg" + count);
    obj.style.display = "block";
    btn = document.getElementById("btnad" + count);
    btn.style.backgroundColor = "Gray";
    count++;
    if (count > 4) count = 1;
    pid = setInterval(autoSelect, delay);
}

function playAD() {
    var button = document.getElementById("btnControl");
    if (button.innerHTML == "&gt;") {
        button.innerHTML = "||";
        autoSelect();
    } else {
        if (pid != null) clearInterval(pid);
        button.innerHTML = "&gt;";
    }
}

autoSelect();
