var timerVisore;
var indexSlide = 1;
var maxSlide = 1;
var SlideShow;
var stopSlideshow = false;

function SlidePreload() {
	var images = new Array();

	for(var i = 0; i < SlideShow.length; i++) {
		images[i] = new Image();
		images[i].src = SlideShow[i][1];
	}

	SlideshowStart();
}

function SlideshowStart() {
	stopSlideshow = false;
	timerVisore = setTimeout("SlideshowPlay(" + (indexSlide + 1) + ")", SlideShow[indexSlide - 1][0]);
}

function SlideshowStop(i) {
	stopSlideshow = true;
	clearTimeout(timerVisore);

	if(i != indexSlide) {
		$j("#slide" + i).show();
		$j("#slideNum" + i).attr("src", "images/pallino_rosso.png");
		$j("#slide" + indexSlide).hide();
		$j("#slideNum" + indexSlide).attr("src", "images/pallino_grigio.png");
		indexSlide = i;
	}
}

function SlideshowPlay(i) {
	if(stopSlideshow) return;
	
	if(i > maxSlide) i = 1;

	$j("#slide" + indexSlide).fadeOut("slow", function () {
		$j("#slideNum" + indexSlide).attr("src", "images/pallino_grigio.png");
		$j("#slide" + i).fadeIn("slow");
		$j("#slideNum" + i).attr("src", "images/pallino_rosso.png");
		indexSlide = i;
		timerVisore = setTimeout("SlideshowPlay(" + (indexSlide + 1) + ")", SlideShow[indexSlide - 1][0]);
	});
}

function SlideClick() {
	loc = $j("#slide" + indexSlide + " a").attr("href");
	// alert(loc);
	MM_openBrWindow(loc,'','');
}

$j(document).ready(function() {
	SlidePreload();
});
