var smooth_image_number=new Array();
var smooth_timer=new Array();
var starter_image=new Array();

function effect_image_start(key,thumbnail_list_max_count,smooth_count)
{
	smooth_image_number[key]=0;
	smooth_timer[key]=null;

	thumbnail_list_count=0;
	for(var i=1; i<=thumbnail_list_max_count; i++){
		if(!document.getElementById('effect_image_'+key+'_thumbnail_'+i)){
			break;
		}
		thumbnail_list_count++;
	}
	for(var i=1; i<=thumbnail_list_max_count; i++){
		if(!document.getElementById('effect_image_'+key+'_thumbnail_btn_'+i)){
			break;
		}
		thumbnail_list_count++;
	}

	for(var i=1; i<=thumbnail_list_count; i++){
		$('#effect_image_'+key+'_thumbnail_'+i).click(
			function (e) {
				var id=e.target.getAttribute("id");
				var click_index=parseInt(id.replace('effect_image_'+key+'_thumbnail_',''),10);
				for(var j=1; j<=thumbnail_list_count; j++){
					var image_id='#effect_image_'+key+'_'+j;
					var li_id='#effect_image_li_'+key+'_'+j;
					var button_id='effect_image_'+key+'_thumbnail_btn_'+j;
					if(click_index==j){
						$(image_id).css("z-index","2");
						$(li_id).css("z-index","2");
						$(image_id).fadeTo("slow", 1);
						if(document.getElementById(button_id)){
							document.getElementById(button_id).src=document.getElementById(button_id).src.replace('_off','_on');
						}
						smooth_image_number[key]=click_index;
					}else{
						$(image_id).css("z-index","0");
						$(li_id).css("z-index","0");
						$(image_id).fadeTo("slow", 0);
						if(document.getElementById(button_id)){
							document.getElementById(button_id).src=document.getElementById(button_id).src.replace('_on','_off');
						}
					}
				}
				smooth_seek(smooth_count);
				clearInterval(smooth_timer[key]);
				smooth_timer[key] = setInterval('smooth_display('+key+','+thumbnail_list_count+','+smooth_count+')',smooth_count);
			}
		);
		$('#effect_image_'+key+'_thumbnail_btn_'+i).click(
			function (e) {
				var id=e.target.getAttribute("id");
				var click_index=parseInt(id.replace('effect_image_'+key+'_thumbnail_btn_',''),10);
				for(var j=1; j<=thumbnail_list_count; j++){
					var image_id='#effect_image_'+key+'_'+j;
					var li_id='#effect_image_li_'+key+'_'+j;
					var button_id='effect_image_'+key+'_thumbnail_btn_'+j;
					if(click_index==j){
						$(image_id).css("z-index","2");
						$(li_id).css("z-index","2");
						$(image_id).fadeTo("slow", 1);
						if(document.getElementById(button_id)){
							document.getElementById(button_id).src=document.getElementById(button_id).src.replace('_off','_on');
						}
						smooth_image_number[key]=click_index;
					}else{
						$(image_id).css("z-index","0");
						$(li_id).css("z-index","0");
						$(image_id).fadeTo("slow", 0);
						if(document.getElementById(button_id)){
							document.getElementById(button_id).src=document.getElementById(button_id).src.replace('_on','_off');
						}
					}
				}
				smooth_seek(smooth_count);
				clearInterval(smooth_timer[key]);
				smooth_timer[key] = setInterval('smooth_display('+key+','+thumbnail_list_count+','+smooth_count+')',smooth_count);
			}
		);
	}

	$('#effect_image_'+key+'_thumbnail_list').children().hover(function() {
		$(this).siblings().stop().fadeTo(400,0.5);
	}, function() {
		$(this).siblings().stop().fadeTo(400,1);
	});

	starter_image[key]=1;
	smooth_display(key,thumbnail_list_count,smooth_count);
}

function smooth_display(key,thumbnail_list_count,smooth_count)
{
	smooth_image_number[key] += 1;
	if(smooth_image_number[key] > thumbnail_list_count){
		smooth_image_number[key] = 1;
	}
	for(i=1; i<=thumbnail_list_count; i++){
		var image_id='#effect_image_'+key+'_'+i;
		var li_id='#effect_image_li_'+key+'_'+i;
		var button_id='effect_image_'+key+'_thumbnail_btn_'+i;
		if(smooth_image_number[key] == i){ 
			$(image_id).css("z-index","2");
			$(li_id).css("z-index","2");
			$(image_id).fadeTo("slow", 1);
			if(document.getElementById(button_id)){
				document.getElementById(button_id).src=document.getElementById(button_id).src.replace('_off','_on');
			}
		}else{
			$(li_id).css("z-index","0");
			$(image_id).css("z-index","0");
			$(image_id).fadeTo("slow", 0);
			if(document.getElementById(button_id)){
				document.getElementById(button_id).src=document.getElementById(button_id).src.replace('_on','_off');
			}
		}
	}

	smooth_seek(smooth_count);

	if(starter_image[key] == 1){
		starter_image[key]=0;
		clearInterval(smooth_timer[key]);
		smooth_timer[key] = setInterval('smooth_display("'+key+'",'+thumbnail_list_count+','+smooth_count+')',smooth_count);
	}
}

function smooth_seek(smooth_count){
	// シークバーアニメーション
	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");
}

