var timeGlobalInput = 100;
var timerArray = null;
var nIndex = 0;
var timerID = null;
var aArray = null;
var arrLength = 0;
var setRotateTimeOut = null;
var rotateplaceHolder = null;

function preloadRotatingImages(divId) {
    //alert('test');
    var divRotate = $(divId);
    if (divRotate != null) {
        //alert('founddiv');
        var els = divRotate.getElementsByTagName("img");
        var elsLen = els.length;
        //alert(els.length);
        for (i = 0, j = 0; i < elsLen; i++) {
            //alert(els[i].src);
            MM_preloadImages(els[i].src);
            j++;
        }
    }

}    

function makeContent(c) {
    this.copy = c;
    this.write = writeContent;
}

function writeContent() {
    var str = '';
    str += this.copy;
    return str;
}

function testthis() {
    alert('rotate');
}
function goRotateContent() {
    rotateContent(rotateplaceHolder, null, null);
}

function rotateContent(what,timeArray, theArray) {

    var contentFromArray;
    var divTest;
    if (rotateplaceHolder == null) {
        rotateplaceHolder = what;
    }
    if (aArray == null) {
        aArray = theArray;
    }
    else {
        if (theArray != null) {
            aArray = theArray;
        }

    }
    if (timerArray ==null) {

        timerArray = timeArray;
    }

    var len = aArray.length;
    var timeInput = timerArray[0];
    //alert('test' + nIndex);
    if (nIndex >= len) {
        //alert('test'+nIndex);
        nIndex = 0;
        timeInput = timerArray[nIndex];
    }

    divTest = $(aArray[ nIndex]);
    //alert(aArray[0, nIndex]);
    
    if (divTest != null) {
        contentFromArray = divTest.innerHTML;        
    }
    document.getElementById(rotateplaceHolder).innerHTML = contentFromArray; //aArray[nIndex];
    timeInput = timerArray[nIndex];
     if (!timeInput)
    {
        timerArray = timeArray;
    }
    nIndex++;
    arrLength = len;
    timeGlobalInput = timeInput;
    if (len > 1) {
        setRotateTimeOut = "rotateContent('" + rotateplaceHolder + "',null,null)";
        timerID = setTimeout(setRotateTimeOut, timeInput);
        //alert("1tid" + timerID);
    }

} //rotateContent



function pauseContent() {
    if (timerID != null) {
        clearTimeout(timerID);
        timerID = null;
    }
}

function playContent(what) {
    if (arrLength > 0) {
        if (timerID == null) {
            setRotateTimeOut = "rotateContent('" + what + "',null,null)";
            timerID = setTimeout(setRotateTimeOut, timeGlobalInput);
        }
    }
}

function rotateContentByIndex(contentIndex) {
    if (contentIndex >= 0) {
        if (contentIndex < arrLength) {
            nIndex = contentIndex;
            //alert(nIndex);
        }
    }
    //alert("tid"+timerID);
    clearTimeout(timerID);
    timerID = null;

    //alert(nIndex);
    goRotateContent();
}


