var slideNr = 0;
var timer;

function nextSlide() {
	slideNr++;
	var totalSlides = $('#slideshow li').length;
	if (slideNr < totalSlides) {
		$('#slideshow li:eq('+slideNr+')').fadeIn('slow');
	} 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').click(function(event) {
		window.clearTimeout(timer);
		timer = window.setTimeout("nextSlide()", 0);	
	});
	/*
	$('#slideshow li').mouseover(function(event) {
		$('#slide-navigation').css('display','block');
	});
	$('#slideshow li').mouseout(function(event) {
		$('#slide-navigation').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');
	$('#slideshow li:first .imgcaption').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(/timthumb\/timthumb\.php\?src=/, '').replace(/&.+$/, ''));
		
		// show description
		var txt = $(this).children("img").attr("alt");
		$("#descr").html(txt);
		
		// show image number
		var title = $(this).attr("title");
		$("#img_title").html('- '+title+' -');
	});
}

