// site.js
var thumbTimeout = 2750;
var nextThumb = 1;
var runningTimer;

function pageLoad() {

	thumbs.pop();

  var el = document.getElementById('rotate');
  
  el.className = "rotate";
  
  while (el.firstChild) { el.removeChild(el.firstChild); }
  for(var i=0; i<thumbs.length; i++) {
    var t = document.getElementById(thumbs[i]);
	if ((t!=null))
	{
	    t.style.position = 'absolute';
	    t.style.visibility = 'hidden';
	    el.appendChild(t);
	}
  }
  el.firstChild.style.visibility = 'visible';
  runningTimer = window.setTimeout(startFading, thumbTimeout);
}

function startFading() {
  var el = document.getElementById('rotate').childNodes[nextThumb];
  el.style.visibility = 'visible';
  el.style.zIndex = 2;
  setOpacity(el, 0);
  fadeThumb(el,0);
  nextThumb = (nextThumb < thumbs.length-1) ? nextThumb + 1 : 0;
}

function fadeThumb(el, currentOpacity) {
  
  var prevEl = el.previousSibling ? el.previousSibling : el.parentNode.lastChild;
  currentOpacity += 5;
  if (currentOpacity > 100) {
    setOpacity(el, 100);
    prevEl.style.visibility = 'hidden';
    el.style.zIndex = 1;
    runningTimer = window.setTimeout(startFading, thumbTimeout);
  }
  else {
    setOpacity(el, currentOpacity);
	setOpacity(prevEl, (100 - currentOpacity));
    runningTimer = window.setTimeout(function() { fadeThumb(el, currentOpacity); }, 50);
  }
}

function setOpacity(el, opacity) {
	opacity /= 100;
	el.style.opacity = opacity;
	el.style.MozOpacity = opacity;
	el.style.filter = "alpha(opacity=" + (opacity*100) + ")";
}

function rotatePause()
{
	clearTimeout(runningTimer);
}

function rotateStart()
{
	runningTimer = window.setTimeout(startFading, thumbTimeout);
}
