var speed = 1000;
var imageCount = 0;
var counter = 0;

$(document).ready(function(){
	$("#main.grid div.holder").hover(function(){
		$(this).addClass("hover");
	},function(){
		$(this).removeClass("hover");
	});
	
	imageCount = $('.news_gallery .right li').length;
	if(imageCount > 1) {
		$('#gallery_trigger').fadeIn(speed/3);
	}
	
	$('#gallery_trigger').click(function(event){
		start_gallery();
	});
});

function start_gallery() {
	counter = 1;
	
	$('#gallery_trigger').fadeOut(speed/3);
	setTimeout('gallery_step()', speed);
}

function gallery_step() {
	$('.news_gallery .right li:nth-child('+counter+')').fadeOut(speed/3);
	counter++;
	$('.news_gallery .right li:nth-child('+counter+')').fadeIn(speed/3, function(){
		if(counter < imageCount) {
			setTimeout('gallery_step()', speed);
		} else {
			setTimeout('reset_gallery()', speed);
		}
	});
}

function reset_gallery() {
	$('.news_gallery .right li:nth-child('+counter+')').fadeOut(speed/3);
	$('.news_gallery .right li:nth-child(1)').fadeIn(speed/3);
	$('#gallery_trigger').fadeIn(speed/3);
}
