rotatorMax = new Array();
rotatorCurrent = new Array();

function rotator(name,doRandom) {
	rotatorMax[name] = 1;
	while (document.getElementById(name+rotatorMax[name])) rotatorMax[name]++;
	rotatorMax[name]--;
	document.write('<div id="'+name+'" class="displayRotator"></div>');
	if(doRandom) { rotatorCurrent[name] = 0; rotator_rand(name); }
	else rotator_view(name,1);
}

function rotator_next(name) {
	rotator_view(name,rotatorCurrent[name]+1);
}

function rotator_prev(name) {
	rotator_view(name,rotatorCurrent[name]-1);
}

function rotator_rand(name) {
	var rand = rotatorCurrent[name];
	if(rotatorMax[name]>1) while(rand==rotatorCurrent[name]) rand=Math.floor((Math.random()*rotatorMax[name])+1);
	rotator_view(name,rand);
}


function rotator_view(name,id) {
	if (id==0) {
		id=rotatorMax[name];
	}
	else if (id>rotatorMax[name]) {
		id=1;
	}
	if (id == rotatorMax[name]) {
		document.getElementById("next").className = "hide";
	} else 
		document.getElementById("next").className = "show";
	if (document.getElementById("controls")) {
		document.getElementById(name).innerHTML = document.getElementById(name+id).innerHTML + document.getElementById("controls").innerHTML;
	}
	else if (document.getElementById("controls_first")) { //this is used on the Student Affairs homepage for the blueprint display
		divcontent = document.getElementById(name+id).innerHTML;
		imgcontrols("</a>");
		document.getElementById(name).innerHTML = firstcontent + document.getElementById("controls_first").innerHTML + secondcontent;
	}
	else {
		document.getElementById(name).innerHTML = document.getElementById(name+id).innerHTML + document.getElementById("controls").innerHTML;
	}
	rotatorCurrent[name] = id;
	document.getElementById("previous").className = "show";
}


function imgcontrols(cutter) {
	cut_at = divcontent.indexOf(cutter);
	firstcontent = divcontent.substring(0,cut_at);
	secondcontent = divcontent.substring(cut_at);
}
