//Author:				Tim Miller
//Date:					8/6/2004
//Filename:				divRotator.js
//
//Description:			This file rotates through an array of divs on a page.
//
//Editing instructions:	-Set slideRefreshTime variable to number of seconds between slides.
//						-Fill divArray with divs to be rotated through.
//*********************************************************

//seconds between slides in slideshow
var slideRefreshTime = 5;

var divArray = new Array();
divArray[0] = "centersContent1";
divArray[1] = "centersContent2";
divArray[2] = "centersContent3";

var buttonArray = new Array();
buttonArray[0] = "centers1";
buttonArray[1] = "centers2";
buttonArray[2] = "centers3";


//*********************************************************
//do not edit below this line
//*********************************************************

var prev;
var slideShow = true;
var thisRefreshTime = slideRefreshTime*1000;

function nextDiv(current){
	if(current == divArray.length-1){
		next = 0;
	}else{
		next = parseInt(current)+1;
	}
	
	for(i = 0; i < divArray.length; i++){
		if(i != current){
			eval('document.getElementById("'+divArray[i]+'").className = "centersContent_off"');
			eval('document.getElementById("'+buttonArray[i]+'").className = "centersButton_off"');
		}
	}
	
	eval('document.getElementById("'+divArray[current]+'").className = "centersContent"');
	eval('document.getElementById("'+buttonArray[current]+'").className = "centersButton"');
	opacity(divArray[current], 0, 100, 1000);
	
	if(slideShow){
		timeoutid = setTimeout('nextDiv('+next+')',thisRefreshTime);
	}
}

function slideShowOff(){
	if (slideShow) {
		slideShow = false;
		clearTimeout(timeoutid);
	}
}

function showNextDiv(){
	if (slideShow) {
		clearTimeout(timeoutid);
		nextDiv(next);
	}else{
		nextDiv(next);
	}
}

function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}