﻿var count = data.length;
var current = Math.floor(Math.random() * count);
var next = (current + 1) % count;
var active = true;

$("#img0").attr("src", data[current][0]);
$("#txt0").html(data[current][1]);
$("#img1").attr("src", data[next][0]);
$("#txt1").html(data[next][1]);

function switchBanner() {
    next = (current + 2) % count;
    if (active) {
        $("#img0").fadeOut(500, function() { $("#img0").attr("src", data[next][0]); });
        $("#img1").fadeIn(500);
        $("#txt0").fadeOut(500, function() { $("#txt0").html(data[next][1]) });
        $("#txt1").fadeIn(500);
    }
    else {
        $("#img1").fadeOut(500, function() { $("#img1").attr("src", data[next][0]); });
        $("#img0").fadeIn(500);
        $("#txt1").fadeOut(500, function() { $("#txt1").html(data[next][1]) });
        $("#txt0").fadeIn(500);
    }
    current = (current + 1) % count;
    active = !active;
}

$(document).ready(function() {
    setInterval(switchBanner, 10000);
});
