var timer = "";			// our timer
var timerSeconds = 6;	// interval between switches
var timerOn = 1;		// which element are we on currently
var lastSpotlight = 0;		// the last element
var playing = true;

function swap(el) {
	// they clicked, clear mouseover
	lastSpotlight = 0;
	if ( playing === false ) playing = true; // we want the playPause() to pause
	playPause();
	change(el);
}

function change(idx) {
	timerOn = idx;
  
  for( var i=1; i<=7; i++ ) {
    var el = document.getElementById('spotlight'+i);
    if( el ) el.style.display = (i===idx ? "block" : "none");
  }
}

function startTimer() {
	if ( timer === "" ) timer = setTimeout("doTimer()", timerSeconds * 1000)
}

function doTimer() {
	timer = "";
	if ( playing === true && lastSpotlight === 0 ) {
		timerOn++;
		if ( timerOn === 8 ) {
			timerOn = 1;
		}
		change(timerOn);
		startTimer();
	}
}

function playPause() {
	if( playing === true ) {
		timer = "";
		playing = false;
	} else {
		startTimer();
		playing = true;
	}
  
  for( var i=1; i<=7; i++ ) {
    var el = document.getElementById('imgPlayPause'+i);
    if( el ) el.src = (playing ? "/files/NPE2012/PageLayoutImages/hbn_Pause.gif" : "/files/NPE2012/PageLayoutImages/hbn_Play.gif");
  }
}

function spotlightOver(el) {
	lastSpotlight = timerOn;
//	playPause();
	change(el);
}

function spotlightOut() {
	if ( lastSpotlight > 0 ) {
		change(lastSpotlight);
		lastSpotlight = 0;
		startTimer();
	}
}

startTimer();

