$(document).ready(function(){
	/* main block */
	var fadeint = 500;
	var loopint = ($('body').hasClass('de')) ? 15000 : 10000;

	$('<div class="timer">').prependTo($('#animation ol li'));
	
	setTimer();

	var loop = setInterval(function(){
		$('#animation .section.active').removeClass('active').fadeOut(fadeint, function(){
			if($(this).next('.section').size()){
				$(this).next().fadeIn(fadeint).addClass('active');
			}
			else{
				$('#animation .section').eq(0).fadeIn(fadeint).addClass('active');
			}
		});
		
		$('.background-wrapper img.active').removeClass('active').fadeOut(0, function(){
			if( $(this).next('img').size() ){
				$(this).next().show().addClass('active');
			}
			else{
				$('.background-wrapper img').eq(0).show().addClass('active');
			}			
		});
		
		$('#animation li.active').removeClass('active').fadeIn(fadeint, function(){
			if($(this).next('li').size()){
				$(this).next().show().addClass('active');
			}
			else{
				$('#animation li').eq(0).show().addClass('active');
			}		
		});

		setTimer();
	}, loopint);

	$('#animation ol li').each(function(index){
		$(this).click(function(){
			clearInterval(loop);
			$(this).parent().find('li').removeClass('active');
			$(this).addClass('active');
			$('#animation .section').removeClass('active').hide().eq(index).addClass('active').fadeIn();
			$('.background-wrapper img').removeClass('active').fadeOut().eq(index).addClass('active').fadeIn();
		});
	});

	/* news block */
	$('#sidebar-right .comments-header .open').toggleClass('on');
	$('#sidebar-right .comments-header .open').click(function(){
		$(this).toggleClass('on');
		$('#sidebar-right .in_the_news').slideToggle('fast');
	});

	$(".in_the_news .item-list").parent().append('<div class="prev"></div><div class="next"></div>');
/*	$(".in_the_news .item-list").jCarouselLite({
		vertical: true,
		circular: false,
		btnNext: ".next",
		btnPrev: ".prev"
	});
*/
	function setTimer(){
		$('#animation .active .timer').show().css({
			'top':0
		}).animate({
			'top': '-16px'
		}, loopint);
	}
});



