var delay=10000; //delay between changes in milliseconds
var primes = new Array(1, 1); //no randomization, thanks
var p = Math.floor(Math.random()*primes.length); //pick a random primes (changes order)

var doRotation = true;  //whether to do it
var selectedDiv=0;
var totalDivs=0;

//hide all the banner divs
function hidebanners() 
{
    for (var i=0; document.getElementById("banner_image"+i); i++) 
    {
        document.getElementById("banner_image"+i).style.display="none";
        document.getElementById("banner_text"+i).style.display="none";
                        //document.getElementById("banner_sel"+i).style.border="none";
    }
}

function rotationcontrol_hide()
{
    //make the foreground color equal the background color
    document.getElementById("rotation_control_prev").style.color = //wrap
    document.getElementById("banner_text" + selectedDiv).style.backgroundColor;
    document.getElementById("rotation_control_next").style.color = //wrap
    document.getElementById("banner_text" + selectedDiv).style.backgroundColor;
}

function rotationcontrol_show()
{
    //make the foreground color white
    document.getElementById("rotation_control_prev").style.color="white";
    document.getElementById("rotation_control_next").style.color="white";
}

//show a given banner
function showbanner(bannerNum) 
{
    var selectedDivObj;
    var myColor;

    hidebanners(); //start fresh

    //add one of each
    selectedDivObj=document.getElementById("banner_image" + bannerNum);
    selectedDivObj.style.display="block";
    selectedDivObj=document.getElementById("banner_text" + bannerNum);
    selectedDivObj.style.display="block";

    document.getElementById("rotation_control_holder").style.backgroundColor = //wrap
    selectedDivObj.style.backgroundColor;
		
    if (doRotation)
    {
        myColor = selectedDivObj.style.backgroundColor;
    }
    else
    {
        myColor = "white";
    }

    document.getElementById("rotation_control_prev").style.color = myColor;
    document.getElementById("rotation_control_next").style.color = myColor;
}
        
        // goto the previous banner
function prev()
{
    selectedDiv = (totalDivs + (selectedDiv - 1)) % totalDivs;
    showbanner(selectedDiv);
}

        // goto the next banner
function next()
{
    selectedDiv = (selectedDiv + 1) % totalDivs;
    showbanner(selectedDiv);
}
        
        //rotate and schedule the next rotation
function rotate()
{
    if (!doRotation) //mouse is over box
    {
        setTimeout("rotate()", delay);
        return;
    }
               
    selectedDiv= (selectedDiv+primes[p]) % totalDivs;  //go to next one
    showbanner(selectedDiv);
    setTimeout("rotate()", delay);
}

function showsingle(bannernum)
{
    stoprotation();
    showbanner(bannernum);
}

function stoprotation()
{
    doRotation = false;
}

function startrotation()
{
    if (doRotation) return;        //dont start if its started
    doRotation = true;
}

function initrotation() {
    while (document.getElementById("banner_image"+totalDivs)!=null)
    {
        totalDivs++;
    }
                
    document.getElementById("rot_holder").innerHTML = "&nbsp;<!--" + totalDivs + "-->&nbsp;";   
    selectedDiv=Math.floor(Math.random()*totalDivs); //pick random one to start

    rotate();
}
