Before answering your question, I have to say this is a really bad practice, you can use jQuery and a jQuery Slider Plugin, it will be more effective.
doing what you want is beeing more complicated with iframes, but you can do it. you should use iframe onload event for changing current page index(i),
here is how you can do,
<script type="text/javascript">
var pages=new Array();
pages[0]="/budget.html";
pages[1]="/voluntary.html";
pages[2]="/robust.html";
var i=0;
var time=4000; // this is set in milliseconds
var timer = false;
var timerSetter;
function pageChange() {
document.getElementById("agencyframe").src=pages[i];
i++;
if(i==pages.length) {
i=0;
}
timerSetter = setTimeout("pageChange()",time);
}
function contentChanged(e) {
if (!timer) { pageChange(); timer=true;}
if (timerSetter) {
clearTimeout(timerSetter);
timerSetter = setTimeout("pageChange()",time);
}
var newSrc = e.contentWindow.location.href;
for (var j=0; j < pages.length; j++) {
if (newSrc.match(pages[j])) {
i = j+1;
if(i==pages.length) {
i=0;
}
}
}
}
</script>
And don't forget to set onload attribute for iframe,
<iframe id="agencyframe" onload="contentChanged(this)" src="/budget.html">
</iframe>
UPDATE:
As I understand you want to change iframe page when user click (page zero-page one-page two) on this page.
you can change location of a iframe like this,
document.getElementById("agencyframe").src = "/budget.html";
so change your function like this,
function pageZero() {
document.getElementById("prin_div1").setAttribute("class", "prin_on");
document.getElementById("prin_div2").setAttribute("class", "prin_off");
document.getElementById("prin_div3").setAttribute("class", "prin_off");
document.getElementById("agencyframe").src = pages[0];
}
function pageOne() {
document.getElementById("prin_div1").setAttribute("class", "prin_off");
document.getElementById("prin_div2").setAttribute("class", "prin_on");
document.getElementById("prin_div3").setAttribute("class", "prin_off");
document.getElementById("agencyframe").src = pages[1];
}
function pageTwo() {
document.getElementById("prin_div1").setAttribute("class", "prin_off");
document.getElementById("prin_div2").setAttribute("class", "prin_off");
document.getElementById("prin_div3").setAttribute("class", "prin_on");
document.getElementById("agencyframe").src = pages[2];
}
UPDATE -2:
Change contentChanged
function like this,
function contentChanged(e) {
if (!timer) { pageChange(); timer=true;}
if (timerSetter) {
clearTimeout(timerSetter);
timerSetter = setTimeout("pageChange()",time);
}
var newSrc = e.contentWindow.location.href;
for (var j=0; j < pages.length; j++) {
if (newSrc.match(pages[j])) {
i = j+1;
document.getElementById("prin_div"+i).setAttribute("class", "prin_on");
if(i==pages.length) {
i=0;
}
} else {
document.getElementById("prin_div"+(j+1)).setAttribute("class", "prin_off");
}
}
}