$(function() {
		   buzzSetup();
		   });

/* Buzz controls */
function buzzShow(from, to) {
	selectorFrom = "#buzz ul li:eq(" + from + ")";
	selectorTo = "#buzz ul li:eq(" + to + ")";
	$(selectorFrom).fadeOut(1500);
	for(var i = 0; i < liNodes.length; i++) { 
		liNodes[i].style.display = 'none'
	}
	
	$(selectorTo).fadeIn(1500);
	buzzCurrent = to;
}

function buzzSetup() {
	if($('#buzz')) {
		container = document.getElementById("buzz"); 
		if(container!=null){
			ulNode = container.getElementsByTagName("ul"); 
			ulNode[0].style.display = 'block';
			
			liNodes = container.getElementsByTagName("li"); 
			buzzNum = liNodes.length;
			buzzCurrent = 0;
			for(var i = 0; i < liNodes.length; i++) { 
				liNodes[i].style.display = 'none'
			}
			
			var nextButton = document.createElement('a');
			var prevButton = document.createElement('a');
			
			nextButton.onclick = function(){return buzzNext();};
			prevButton.onclick = function(){return buzzPrev();};
			
			nextButton.id = 'next';
			prevButton.id = 'prev';
			
			container.insertBefore(prevButton, container.firstChild);
			container.insertBefore(nextButton, container.firstChild);
			
			liNodes[buzzCurrent].style.opacity = 1;
			liNodes[buzzCurrent].style.display = 'block';
		}
	}
}

function buzzNext() {
	if (buzzCurrent == (buzzNum-1)) {
		buzzShow(buzzCurrent, 0);
	} else {
		buzzShow(buzzCurrent, (buzzCurrent+1));
	}
	buttonPressed=true;
}
function buzzPrev() {
	if (buzzCurrent == 0) {
		buzzShow(buzzCurrent, (buzzNum-1));
	} else {
		buzzShow(buzzCurrent, (buzzCurrent-1));
	}
	buttonPressed=true;
}