function nextImage(){
	current_img = $("#main-image img:visible")
	klass = $(current_img).attr("class")
	num = parseInt(klass.split("")[3]) // klass format == "img1", "img2" etc...
	thumbs_count = $("#thumbs a").size()
	if (num == thumbs_count){
		next = 1
	} else {
		next = num + 1
	}
	$(current_img).fadeOut()
	$("#main-image img.img"+next).fadeIn()
	return true;
}

$(document).ready(function(){
	interval = setInterval(nextImage, 5000)
	var main_window = $("#main-image")
	$("#thumbs a").each(function(){
		$(this).click(function(){
			clearInterval(interval);
			klass = $(this).attr("class")
			current = $(main_window).find("img:visible")
			next = $(main_window).find("img."+klass)
			if ($(current).attr("class") != $(next).attr("class")){
				$(current).fadeOut()
				$(next).fadeIn()
			}
			return false;
		})
	})

	$("#animation img.img1").bind("mouseover", function(){
		$("#animation img.img2").fadeIn()
	})
	$("#animation img.img2").bind("mouseout", function(){
		$("#animation img.img2").fadeOut()
	})

})
