var rot_d = 1;
var t;

// Call functions every 8 seconds
function timedCount() {
    var max = document.getElementById("rot_count").firstChild.nodeValue;
    loadBG();
    swapClass(rot_d);    
    rot_d=rot_d+1;
    if(rot_d>max) { rot_d=1;}
    t=setTimeout("timedCount()",8000);
}

// Load background image for image dissolve
function loadBG() {
    document.getElementById('graphic').style.backgroundImage = "";
    var max = document.getElementById("rot_count").firstChild.nodeValue;
    imgDiv = "rot_div"+(rot_d-1);   // Get previous img 
    if (imgDiv == "rot_div"+0){ 
	imgDiv = "rot_div"+max; 
    }
    var bgImg = document.getElementById(imgDiv).getElementsByTagName('img')[0].src;
    var bgUrl = "url('" + bgImg + "')";
    document.getElementById('graphic').style.backgroundImage = bgUrl;
}

// Change visible div, with slow dissolve from previous image
function swapClass(view) {
    var max = document.getElementById("rot_count").firstChild.nodeValue;
    var i = 1;
    while (i <= max) {
	if (i != view) {
	    document.getElementById("rot_div"+i).className = "rot_hide";
	}
	document.getElementById("rot_boxlink"+i).className = "rot_showlink"; 
	i++;
    }
    mydiv = "rot_div"+view;
    document.getElementById(mydiv).style.opacity = "0.01";
    document.getElementById(mydiv).style.filter = "alpha(opacity='1')";
    fade(mydiv, 1, 99,1500);
    document.getElementById(mydiv).className = "rot_show";
    clearTimeout(t);
}

// Change visible div onClick from numbered buttons, no dissolve
function pickDiv(view){
    var max = document.getElementById("rot_count").firstChild.nodeValue;
    var i = 1;
    while (i <= max) {
	if (i != view) {
	    document.getElementById("rot_div"+i).className = "rot_hide";
	}
	document.getElementById("rot_boxlink"+i).className = "rot_showlink"; 
	i++;
    }
    mydiv = "rot_div"+view;
    document.getElementById(mydiv).style.opacity = "1";
    document.getElementById(mydiv).style.filter = "alpha(opacity='100')";
    document.getElementById(mydiv).className = "rot_show";
    clearTimeout(t);
}

// Set opacity level of div
function setOpacity(eID, opacityLevel) {
          var eStyle = document.getElementById(eID).style;
          eStyle.opacity = opacityLevel / 100;
	  eStyle.filter = 'alpha(opacity='+opacityLevel+')';
      }

// Fade div
function fade(eID, startOpacity, stopOpacity, duration) {
          var speed = Math.round(duration / 100);
          var timer = 0;
          if (startOpacity < stopOpacity){ // fade in
              for (var i=startOpacity; i<=stopOpacity; i++) {
                  setTimeout("setOpacity('"+eID+"',"+i+")", timer * speed);
                  timer++;
              } return;
          }
          for (var i=startOpacity; i>=stopOpacity; i--) { // fade out
              setTimeout("setOpacity('"+eID+"',"+i+")", timer * speed);
              timer++;
          }
      }

