/*  Rotating Buzz Panel Add-On  */

//Add this script to the page if the buzz panel needs to be rotated.  Be sure to include a #pause element inside your center css otherwise the code will not work.  For an example check /discoverypark/css/sbbcle.css

//Change these variables to alter the image path of your pause button as needed:
var PAUSE_BUZZ_IMG = "url(/discoverypark/images/contPlayBtnSbbcle-blue.gif) no-repeat center center";
var CONTPLAY_BUZZ_IMG = "url(/discoverypark/images/pauseBtnSbbcle-blue.gif) no-repeat center center";

//Change this variable to alter the duration between buzz element swaps (in milliseconds) as needed:
var SWAP_TIME = 5000;

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//Necessary global variables 
var timeElapsed = 0;
var paused = false;

//Adds necessary extra controls
function addMoreControls(){
	container = document.getElementById("buzz"); 
	
	var pauseButton = document.createElement('a');
	pauseButton.onclick = function(){return pauseResume();};
	pauseButton.id = 'pause';
	container.insertBefore(pauseButton, container.firstChild);
}

//Handles pause button clicks
function pauseResume(){
	if(paused!=true){
		paused = true;
		document.getElementById("pause").style.background = PAUSE_BUZZ_IMG;
	}else{
		paused = false;
		buttonPressed = true;
		buzzNext();
		rotateEvents();
		document.getElementById("pause").style.background = CONTPLAY_BUZZ_IMG;
	}
}

//Recursive timing function to give the buzz element a delay between switches
function rotateEvents(){
	var z;
	if(paused!=true){
		if(buttonPressed!=true){
			if(timeElapsed>=SWAP_TIME){
				buzzNext();
				timeElapsed = 0;
			}
			timeElapsed+=100;
		}else{
			buttonPressed = false;
			timeElapsed = 0;
		}
		z=setTimeout(rotateEvents,100);
	}else{
		return 0;
	}
}

//Trigger the functions after loading is complete
window.onDomReady(addMoreControls);
window.onDomReady(rotateEvents);
