/*
 * 環境変数のため変更なし
 */
var thumbnail_list_count=0;
var smooth_image_number=0;
var smooth_timer=null;
var starter_image=0;

/*
 * 環境により変更可能な変数
 */
var thumbnail_list_max_count=8;  // サムネイル表示可能な画像数
var smooth_count=8000;           // ミリ秒指定（5秒=5000）

$(document).ready(function(){

	for(var i=1; i<=thumbnail_list_max_count; i++){
		if(!document.getElementById('thumbnail_image'+i)){
			break;
		}
		thumbnail_list_count++;
	}

	for(var i=1; i<=thumbnail_list_count; i++){
		$("#thumbnail_image"+i).click(
			function (e) {
				var id=e.target.getAttribute("id");
				var click_index=parseInt(id.replace('thumbnail_image',''),10);
				for(var j=1; j<=thumbnail_list_count; j++){
					if(click_index==j){
						$("#top_image"+j).fadeTo("slow", 1);
						smooth_image_number=click_index;
					}else{
						$("#top_image"+j).fadeTo("slow", 0);
					}
				}
				smooth_seek();
				clearInterval(smooth_timer);
				smooth_timer = setInterval("smooth_display()",smooth_count);
			}
		);
	}

	$("#thumbnail_list").children().hover(function() {
		$(this).siblings().stop().fadeTo(400,0.5);
	}, function() {
		$(this).siblings().stop().fadeTo(400,1);
	});

	smooth_display();
});

function smooth_display(){
	smooth_image_number += 1;
	if(smooth_image_number > thumbnail_list_count){
		smooth_image_number = 1;
	}
	for(i=1; i<=thumbnail_list_count; i++){
		image_id="#top_image"+i;
		if(smooth_image_number == i){ 
			$(image_id).css("z-index","2");
			$(image_id).fadeTo("slow", 1);
		}else{
			$(image_id).css("z-index","0");
			$(image_id).fadeTo("slow", 0);
		}
	}
	
	smooth_seek();
	
	starter_image=1;
	if(starter_image == 1){
		clearInterval(smooth_timer);
		smooth_timer = setInterval("smooth_display()",smooth_count);
	}
}

function smooth_seek(){
	// シークバーアニメーション
	var bar_width=$('#top_image_seek_bar_area').width();
	$('#top_image_seek_bar').stop();
	$('#top_image_seek_bar').width(0);
	$('#top_image_seek_bar').animate({width:bar_width},smooth_count,"linear");
}
