var totalSlides = 0;
var currentSlide = 1;
var buttonsVisible = true;

$(document).ready(function(){
	$("#previous").click(showPreviousSlide);
	$("#next").click(showNextSlide);
	$("#slideshow").hover(toggleButtons);
	
	$("#images img").hide();
	$("#images img:nth-child(1)").fadeIn();
	totalSlides = $("#images img").length;
	updateButtons();
	toggleButtons();
	updateSlides();
});

function  showPreviousSlide()
{
	currentSlide--;
	updateSlides();
	updateButtons();
}

function showNextSlide()
{
	currentSlide++;
	updateSlides();
	updateButtons();
}

function updateSlides()
{
	$("#images img").hide();
	$("#images img:nth-child("+currentSlide+")").fadeIn();
	alt = $("#images img:nth-child("+currentSlide+")").attr("alt");
	$("#count").replaceWith("<div id=\"count\" class=\"centerBox\">"+currentSlide+" / "+totalSlides+"</div>");
	//$("#info").replaceWith("<div id=\"info\" class=\"centerBox\">"+alt+"</div>");
}

function toggleButtons() {
	if(buttonsVisible) {
		$("#buttons").fadeOut();
		buttonsVisible = false;
	}else {
		$("#buttons").fadeIn();
		buttonsVisible = true;
	}
}
function updateButtons()
{
	if(currentSlide < totalSlides) {
		$("#next").show();
	} else {
		$("#next").hide();
	}
	if(currentSlide > 1) {
		$("#previous").show();
	} else {
		$("#previous").hide();
	}
}
