var current  = 1;
var timeout  = 5000;
var interval = ""
var screenshots_count = '';

$(document).ready(function() {
	screenshots_count = $("#screenshot li").length;
	
	var screenshot = $("#screenshot > *");
	screenshot.each (
		function (intIndex) {
			if (intIndex != 0) $(this).hide();
		}
	)
	
	var screenshot_info = $("#screenshot_info > *");
	screenshot_info.each (
		function (intIndex) {
			$(this).bind (
				"click",
				function(){	
					screenshot_info.each (
						function (intIndex) {
							$(this).removeClass("active");
						}
					);
					
					$(this).addClass("active");
					showCurrent(intIndex + 1);
				}
			);

		}
	)
	
	sliderInterval();
});

function sliderInterval () {
	if (screenshots_count > 1) {
		interval = setInterval('showNext()',timeout);
	}
}

function showCurrent (show) {
	clearInterval(interval);
	
	if(show != current) {
		$("#screenshot_" + current).fadeOut();
		$("#screenshot_" + show).fadeIn();
	}
	
	current = show;
	sliderInterval();
}

function showNext () {
	$("#screenshot_" + current).fadeOut();
	
	$("#screenshot_info_" + current).removeClass("active");
	
	if (current == screenshots_count) {
		current = 1;
	} else {
		current++;
	}
	
	$("#screenshot_" + current).fadeIn();
	$("#screenshot_info_" + current).addClass("active");
}
