var ecount;
var ecurrent = 1;

function event() {
    ecurrent = ( ecurrent % ecount ) + 1;
    dojo.byId('upcoming').innerHTML = events[ecurrent - 1];
}


var count1 = 14;
var count2 = 15;
var count3 = 14;
var current1 = 1;
var current2 = 1;
var current3 = 1;
var active = 1;
var swapTimer;
var transTimer;

function swap() {

    swapTimer.stop();

    current1 = ( current1 % count1 ) + 1;
    current2 = ( current2 % count2 ) + 1;
    current3 = ( current3 % count3 ) + 1;

    if (active == 1) {
        dojo.byId('slideshowimage2').src = "/images/slideshows/1/" + current1 + ".jpg";
        dojo.byId('slideshowimage4').src = "/images/slideshows/2/" + current2 + ".jpg";
        dojo.byId('slideshowimage6').src = "/images/slideshows/3/" + current3 + ".jpg";
    } else {
        dojo.byId('slideshowimage1').src = "/images/slideshows/1/" + current1 + ".jpg";
        dojo.byId('slideshowimage3').src = "/images/slideshows/2/" + current2 + ".jpg";
        dojo.byId('slideshowimage5').src = "/images/slideshows/3/" + current3 + ".jpg";
    }

    //event();
    transTimer.start();
}

function transition() {

    transTimer.stop();

    if (active == 1) {

        dojo.fadeOut({node: "slideshowimage1", duration: 500}).play();
        dojo.fadeIn({node: "slideshowimage2", duration: 500}).play();

        dojo.fadeOut({node: "slideshowimage3", duration: 500}).play();
        dojo.fadeIn({node: "slideshowimage4", duration: 500}).play();

        dojo.fadeOut({node: "slideshowimage5", duration: 500}).play();
        dojo.fadeIn({node: "slideshowimage6", duration: 500}).play();

        active = 2;

        event();

    } else {

        dojo.fadeOut({node: "slideshowimage2", duration: 500}).play();
        dojo.fadeIn({node: "slideshowimage1", duration: 500}).play();

        dojo.fadeOut({node: "slideshowimage4", duration: 500}).play();
        dojo.fadeIn({node: "slideshowimage3", duration: 500}).play();

        dojo.fadeOut({node: "slideshowimage6", duration: 500}).play();
        dojo.fadeIn({node: "slideshowimage5", duration: 500}).play();

        active = 1;

    }

    swapTimer.start();
}

dojo.require("dojo.fx");
dojo.addOnLoad(function() {
    swapTimer = new dojox.timing.Timer(600);
    swapTimer.onTick = function () { swap(); };
    transTimer = new dojox.timing.Timer(1800);
    transTimer.onTick = function () { transition(); };
    swap();

    ecount = events.length;
    //dojo.byId('event1').innerHTML = events[0];
    //dojo.byId('event2').innerHTML = events[1];
    /*eTimer = new dojox.timing.Timer(2400);
    eTimer.onTick = function () { event(); };
    eTimer.start();*/
});