
var enabled = false;
var arr = new Array();
curIndex = 0;

var init = false;
var playing = true;

var playbtn = new Image();
var pausebtn = new Image();
var delay = 10000;

playbtn.src = "/images/clubsites/mediawall_controls_play.gif";
pausebtn.src = "/images/clubsites/mediawall_controls_pause.gif";

function getIndex(i) {
    if (i>0){
        curIndex = ((curIndex + 1) == arr.length) ? 0 : curIndex + 1;
    }else{
        curIndex = (curIndex == 0)? arr.length - 1 : curIndex - 1;
    }
    return curIndex;
}

function loadModule(i) {
    clearTimeout(timerID);
    if(mw && enabled){
        enabled = false;
        mw.document.location.replace(arr[getIndex(i)]);
    }
}

function pauseRotate() {
    clearTimeout(timerID);
    playing = false;
}


function playRotate(len) {

    if (init) {
        timerID = setTimeout("loadModule(1)",delay);
        playing = true;
    }
	else {
      togglePlay();
    }
}

function togglePlay() {
    if (document.getElementById) imgObj = mw.document.getElementById('play_pause'); // ie5/ns6
    else if (document.layers) imgObj = mw.document.container.document.controls.document.play_pause; // ns4
    else imgObj = document.play_pause; // ie4
    if (playing) {
        pauseRotate(); 
        imgObj.src = playbtn.src;             
    }
    else {
        playRotate(0);
        imgObj.src = pausebtn.src;     
    }
}

function setRotation(rArr) {
    if (rArr) arr = rArr;
    init = true;
    enabled = true;
    if (playing && arr.length > 1) playRotate(arr.length);
}


