var currentpage
var contentDiv
var fadeInterval
var rootDivID

//initialize function to be called from html 
function initSlideShow(ParentDivID, TimeInterval) {
    rootDivID = ParentDivID
    fadeInterval = TimeInterval    
}


function startSlideShow() {

    contentDiv = document.getElementById(rootDivID).getElementsByTagName("div");

    //set zIndex for all child div's and set display none
    for (var count = 0; count < contentDiv.length; count++) {
        contentDiv[count].style.zIndex = contentDiv.length - count;
        contentDiv[count].style.display = 'none';
    }

    //set visibility for first div element 
      contentDiv[0].style.display = 'block';
  currentpage = 1;

    //Initialize Timer
    window.setTimeout("changeZIndex()", fadeInterval);

}

function changeZIndex() {

    var count = 0;

    //Start change zIndex for child div's

    for (var i = currentpage; i < contentDiv.length; i++) {
        contentDiv[i].style.zIndex = contentDiv.length - count;
        count++;
    }

    for (var i = 0; i <= currentpage - 1; i++) {
        contentDiv[i].style.zIndex = contentDiv.length - count;
        count++;
    }

    //End change zIndex for child div's

    //Set visibility
    for (var i = 0; i < contentDiv.length; i++) {

        if (i == currentpage)
            contentDiv[i].style.display = 'block';
        else
            contentDiv[i].style.display = 'none';
    }


    currentpage++;
    if (currentpage == contentDiv.length)
        currentpage = 0;

    window.setTimeout("changeZIndex()", fadeInterval);
}

window.onload = function () { startSlideShow() }

