var slideShowFoto = [
{
"image" : "http://www.axelroma.it/cms_files/slideshow/W94J_08022012113911.jpg",
"cont" : ''
},{
"image" : "http://www.axelroma.it/cms_files/slideshow/4LAP_17022012134326.jpg",
"cont" : '<a href="http://www.youtube.com/v/T1mmTgpi3q0" class="nyroModal" title="scopri axel, la pista del ghiaccio al centro di roma" target="_blank"><img alt="scopri axel, la pista del ghiaccio al centro di roma" src="css/css-index/backSlide/go.png"  border="0" /></a>'
},{
"image" : "http://www.axelroma.it/cms_files/slideshow/JQ1R_27122011163913.jpg",
"cont" : '<a href="http://www.axelroma.it/corsi.php" class="nyroModal" title="corsi di pattinaggio e danza" target="_self"><img alt="corsi di pattinaggio e danza" src="css/css-index/backSlide/go.png"  border="0" /></a>'
},{
"image" : "http://www.axelroma.it/cms_files/slideshow/IFAB_21122011142406.jpg",
"cont" : '<a href="http://itunes.apple.com/it/app/axel-roma/id467908890?l=it&amp;ls=1&amp;mt=8" class="nyroModal" title="axel" target="_blank"><img alt="axel" src="css/css-index/backSlide/go.png"  border="0" /></a>'
},{
"image" : "http://www.axelroma.it/cms_files/slideshow/J5ZE_29112011150102.jpg",
"cont" : '<a href="http://www.axelroma.it/fun.php#pattinaggio-libero" class="nyroModal" title="pattinaggio libero" target="_self"><img alt="pattinaggio libero" src="css/css-index/backSlide/go.png"  border="0" /></a>'
}
];
var slideShowMsec = 6000;
$(document).ready(function() {
	$("#slideShowBack").click(function() {
		stopAnimation();
		navigate("slideShowBack");
	});
	$("#slideShowNext").click(function() {
		stopAnimation();
		navigate("slideShowNext");
	});
	var interval;
	$("#slideShowControl").toggle(function(){
		stopAnimation();
	}, function() {
		$(this).css({ "background-image" : "url(css/css-index/backSlide/btn_pause.png)" });
		navigate("slideShowNext");
		interval = setInterval(function() {
			navigate("slideShowNext");
		}, slideShowMsec);
	});
	var activeContainer = 1;
	var currentImg = 0;
	var animating = false;
	var navigate = function(direction) {
		if(animating) {
			return;
		}
		if(direction == "slideShowNext") {
			currentImg++;
			if(currentImg == slideShowFoto.length + 1) {
				currentImg = 1;
			}
		} else {
			currentImg--;
			if(currentImg == 0) {
				currentImg = slideShowFoto.length;
			}
		}
		var currentContainer = activeContainer;
		if(activeContainer == 1) {
			activeContainer = 2;
		} else {
			activeContainer = 1;
		}
		showImage(slideShowFoto[currentImg - 1], currentContainer, activeContainer);
	};
	var currentZindex = -1;
	var showImage = function(photoObject, currentContainer, activeContainer) {
		animating = true;
		currentZindex--;
		$("#slideShowImg" + activeContainer).css({
			"background-image" : "url(" + photoObject.image + ")",
			"display" : "block",
			"z-index" : currentZindex
		});
		$("#slideShowtxt").html(photoObject.cont);
		$("#slideShowImg" + currentContainer).fadeOut(function() {
			setTimeout(function() {
				animating = false;
			}, 500);
		});
	};
	var stopAnimation = function() {
		$("#slideShowControl").css({ "background-image" : "url(css/css-index/backSlide/btn_play.png)" });
		clearInterval(interval);
	};
	navigate("slideShowNext");
	interval = setInterval(function() {
		navigate("slideShowNext");
	}, slideShowMsec);
});

