/* Gallery setup */
var buttonPressed = false;

function startGallery() {
	if($('myGallery')){
		galleryImages = $('myGallery').getElementsByClassName("imageElement");
		/* if there is only one image, this conditional keeps the slide show from playing */
		if (galleryImages.length > 1) {
			var myGallery = new gallery($('myGallery'), {
				timed: true,
				showInfopane: true,
				showArrows: true,
				showCarousel: false,
				showPlay: true
			});
		} else {
			var myGallery = new gallery($('myGallery'), {
				timed: false,
				showInfopane: true,
				showArrows: false,
				showCarousel: false,
				showPlay: false,
				playState: false
			});
		}
	}
}

/* Buzz controls */
function buzzShow(from, to) {
	for(var i = 0; i < liNodes.length; i++) { 
		liNodes[i].style.display = 'none'
	}
	liNodes[to].style.opacity = 0;
	liNodes[to].style.display = '';
	new Fx.Style(liNodes[to], 'opacity', {duration: 1000} ).start(1);
	new Fx.Style(liNodes[from], 'opacity', {duration: 1000} ).start(0);
	//new Moo.Fx.Style(liNodes[to], 'opacity', {duration: 1000} ).start(1); - for namespaced version
	//new Moo.Fx.Style(liNodes[from], 'opacity', {duration: 1000} ).start(0); - for namespaced version
	buzzCurrent = to;
}

function buzzSetup() {
	if($('buzz')) {
		container = document.getElementById("buzz"); 
		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 = 0;
		liNodes[buzzCurrent].style.display = '';
		new Fx.Style(liNodes[buzzCurrent], 'opacity', {duration: 1000} ).start(1);
		//new Moo.Fx.Style(liNodes[buzzCurrent], 'opacity', {duration: 1000} ).start(1); - for namespaced version
	}
}

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;
}

/* Accordian controls */
function accordianSetup() {
	if($('basic-accordian')){
		new Accordian('basic-accordian',3,'header_highlight');
	}
}

window.onDomReady(startGallery);
window.onDomReady(buzzSetup);
window.onDomReady(accordianSetup);