var num_old = 0;
var interval = 6000;

var thumb_max = 4;
var now_last_thumb = thumb_max - 1;

function chgThumb(last_thumb)
{
	if (last_thumb >= (thumb_max - 1) && last_thumb < thumb_count)
	{
		for (var i = 0; i < thumb_count; i++) {
			
			var thumb_li = document.getElementById("thumb_0" + (i + 1));
			if (i <= (last_thumb - thumb_max) || i >last_thumb)
			{
				thumb_li.style.display = "none";
			}
			else thumb_li.style.display = "";
		}
		now_last_thumb = last_thumb;
	}
}


function chgImage(num_new) {
	if (num_old != num_new) {
		document.getElementById("thumb_0" + (num_old + 1)).className = "";
		document.getElementById("thumb_0" + (num_new + 1)).className = "current";
		$("#image_0" + (num_old + 1)).fadeOut("slow");
		$("#image_0" + (num_new + 1)).fadeIn("slow");
		document.getElementById("image_link").href = $("#main_t0" + (num_new + 1)).attr("href");
		num_old = num_new;
	}
}

function autoChgImage() {
	contents_max = thumb_count;
	num_new = (num_old + 1) % contents_max;
	if (num_new > contents_max) num_new = 0;
	chgImage(num_new);
	
	if (num_new <= now_last_thumb - thumb_max ||
		num_new > now_last_thumb)
	{
		if (num_new >= thumb_max)
			last_thumb = num_new;
		else last_thumb = thumb_max - 1;
		chgThumb(last_thumb);
	}
}

function clickPrevBtn() {
	chgThumb(now_last_thumb - 1);
	return false;
}
function clickNextBtn() {
	chgThumb(now_last_thumb + 1);
	return false;
}
