var images = Array(); var links = Array(); var durations = Array(); 
      images[0] = new Image();
      images[0].src = "images/main/img_main_01.jpg";
      images[0].alt = "";
      images[1] = new Image();
      images[1].src = "images/main/img_main_02.jpg";
      images[1].alt = "";
      images[2] = new Image();
      images[2].src = "images/main/img_main_03.jpg";
      images[2].alt = "";
      links[0] = "#";
      links[1] = "#";
      links[2] = "#";             
      durations[0] = "4";
      durations[1] = "4";
      durations[2] = "4";  
var cycler = null;
var pos = -1;
var last_pos = -1;

function changeimage(dir) {
if (last_pos == -1)
    last_pos = 0;
else
    last_pos = pos;

    switch (dir) {
        case 'prev':
            pos--;
            if (pos < 0) {
                pos = images.length - 1;
            }
        break;
        
        case 'next':
            pos++;
            if (pos > (images.length - 1)) {
                pos = 0;
            }
        break;
    }

    document.getElementById('outerpromobox').style.background = "url(" + images[pos].src + ") no-repeat top left";

    //new Effect.Fade('promoimg', {duration:1, from:1.0, to:0, afterFinish: flipimages});
    new Effect.Fade('promoimg', {duration:1, from:1.0, to:0, afterFinish: flipimages, queue: 'end'});
        
    if (cycler != null) {
        cycler.stop();
    }
    cycler = new PeriodicalExecuter(cycleimages, durations[pos]);
}

function flipimages() {
    var pop_element = document.getElementById('promobox');
    if (links[pos] != "") {
        pop_element.innerHTML = '<a href="' + links[pos] + '"><img src="' + images[pos].src + '" alt="' + images[pos].alt + '" border="0" id="promoimg"></a>';
    } else {
        pop_element.innerHTML = '<img src="' + images[pos].src + '" alt="' + images[pos].alt + '" border="0" id="promoimg">';
    }
}

function cycleimages() {
    changeimage('next');
}
