﻿// JavaScript Document



$(function() {
	var selectMovie;
	var over = false;
	
	SetTab($("#category_movie ul a img:first"));
	
	$("#category_movie ul a").click(function(){
		ReSet();
		SetTab($("img",this));
		return false;
	});
	
	function SetTab(obj){
		var newurl = obj.attr('src').replace('_f.','_over.');
		obj.attr('src', newurl);
		LoadTabContents(obj.parent().attr('href'));
	}
	
	function ReSet(){
		var selector=$("#category_movie ul a img");
		selector.each(function(){ 
			var newurl = $(this).attr('src').replace('_over.','_f.');
			$(this).attr('src', newurl);
		});
	}
	
	function LoadTabContents(tabID){
		$("#tab_list").html('<div class="loader"><img src="img/loader.gif" /></div>');
		$.ajax({
			type: "POST",
			url: "php_script/index_tab.php",
			data: "mode=tab&tab="+tabID,
			success: function(html){
				$("#tab_list").html(html);
			}
		});
	}
	
	$("a[href^=#]").click(function(){
		var Hash = $(this.hash);
		var HashOffset = $(Hash).offset().top;
		$("html,body").animate({
			scrollTop: HashOffset
		}, 500);
		return false;
	});
	
	//新着
	SetNewMovieList(0);
	$("#sub_photo a").hover(
		function () {
			var id = $(this).attr('id').replace('photo_','');
			SetNewMovieList(id);
			over = true;
		},
		function () {
			over = false;
		}
	);
	
	//タイマー
	$.timer(3000, function (timer){
		var nextMovie = eval(selectMovie) + 1;
		if(nextMovie > 3){
			nextMovie = 0;
		}
		SetNewMovieList(nextMovie,timer);
	});
	
	function SetNewMovieList(num,timer){
		if(num != selectMovie && !over){
			$("#sub_photo img").css('border-color','#D3D3D3');
			$("#main_comment div").hide();
			$("#comment" + num).show();
			var src = $("img","#photo_" + num).attr('src');
			$("img","#photo_" + num).css('border-color','#0068B4');
			$("#main_photo img").attr('src',src);
			selectMovie = num;
			
			if(timer){
				timer.reset(5000);
			}
		}
		
	}
	
});















