var current_slide = 0;
var slides_count = null;

$(document).ready(function() {
	// the top menu hovers
/*	$(".menu-top li").hover(function() {
		$(this).children("div").addClass("current");
	}, function() {
		$(this).children("div").removeClass("current");
	});
*/
	$(".slide-thumbs a, .slide .nav a").click(function(e) {
		e.preventDefault();
		if (typeof slideshow != "undefined")
		{
			clearInterval(slideshow);
		}
		change_slide($(this).attr('href').substr(1));
	});

	// initial settings for footer slideshow
	slides_count = $(".mainpage > .slides").children().length;

	// slideshow
	change_slide();
	slideshow = setInterval("change_slide()", 5000);
	
});

function change_slide(slide_number)
{
	if (typeof slide_number != "undefined")
	{
		// change to the specific slide number (i.e. via click)
		current_slide = slide_number;
	}
	else
	{
		// just go to next slide
		current_slide++;
	}

	if (current_slide > slides_count)
	{
		current_slide = 1;
	}

	// load the appropriate slide contents
	var new_slide = $(".slides").children().eq(current_slide - 1);

	// set the teaser
	$(".body-wrapper .slide .teaser").fadeOut(function() {
		$(this).html(new_slide.children(".teaser").html()).fadeIn();
	});
	// set the side logo
	$(".body-wrapper .slide .side-logo").fadeOut("fast", function() {
		$(this).empty().append(new_slide.children(".side-logo").clone().removeClass("side-logo")).fadeIn("fast");
	});
	// set the big background image
	$(".body-wrapper .slide .image").fadeOut("fast", function() {
		$(this).empty().append(new_slide.children(".big-image").clone().removeClass("big-image")).fadeIn("fast");
	});
	// update "zobacz case" link (href attribute)
	$(".body-wrapper .slide .over .see-more").attr("href", new_slide.children("a").attr("href")).attr("title", new_slide.children("a").html());
	// update navigation
	$(".body-wrapper .slide .nav ul li").removeClass("active").eq(current_slide - 1).addClass("active");
	// update the thumbs navigation
	$(".body-wrapper .slide .body .slide-thumbs").children().removeClass("hover").eq(current_slide - 1).addClass("hover");

}

