var slideNr = 0;
var timer;

function nextSlide() {
	slideNr++;
	var totalSlides = $('#slideshow li').length;
	if (slideNr < totalSlides) {
		$('#slideshow li:eq('+slideNr+')').fadeIn('normal');
	} else {
		for (i=1; i < totalSlides-1; i++) {
			$('#slideshow li:eq('+i+')').hide();
		}
		$('#slideshow li:eq('+(totalSlides-1)+')').fadeOut('normal');
		slideNr = 0;
	}
	timer = window.setTimeout("nextSlide()", 4000);
}

window.onload = function() {
	timer = window.setTimeout("nextSlide()", 4000);	
	$('#slideshow li').mouseover(function(event) {
		$('#slideshow li:eq('+slideNr+') img:first').css('display','none');
		$('#slideshow li:eq('+slideNr+') .imgcaption').css('display','block');
		window.clearTimeout(timer);
	});
	$('#slideshow li').mouseout(function(event) {
		$('#slideshow li:eq('+slideNr+') img:first').css('display','block');
		timer = window.setTimeout("nextSlide()", 3000);
		$('#slideshow li:eq('+slideNr+') .imgcaption').css('display','none');
	});
}

function init() {
	// Activate all carousels
	$('.jcarousel').jcarousel({
		scroll: 4
	});
	
	$('#slideshow li').css({'position':'absolute','top':'0','left':'0','display':'none'});
	$('#slideshow li:first').css('display','block');

	// Add Ajax Image Functions
	$('.jcarousel a').click(function(event) {
		event.preventDefault();
		
		// reset all thumbs
		$('.jcarousel li a').removeClass("act");
		
		// highlight act thumb
		$(this).addClass("act");

		// show corresponding big image
		var img = $(this).children("img").attr("src");
		$("#img_big").attr("src",img.replace(/thumb/, "big"));
		
		// show description
		var txt = $(this).children("img").attr("alt");
		$("#descr").html(txt);
		
		// show image number
//		var pos = $(this). ???
		var title = $(this).attr("title");
		$("#img_title").html('- '+title+' -');
	});
}
