// JavaScript Document
var timerN;
$(document).ready(function(){
	//==========▼スクロールバー▽==========
	var posY = 0;
	var cssY = 0;
	var selectObj = null;
	$("#museum_base").mousewheel(function(e){
		return false;
	});
	if($(".bt_inner").find("ul").height() > $(".bt_inner").height() - 45){
		$(".slider").mousedown(function(e){
			cssY = $(this).css("top").replace('px','');
			posY = e.pageY;
			selectObj = this;
			$("body").css("-moz-user-select","none");
			$("body").css("-khtml-user-select","none");
			$("body").css("-webkit-user-select","none");
		});
		$(".slider").parent().parent().parent().mousemove(function(e){
			if(selectObj){
				scrollBar(selectObj,cssY-(posY - e.pageY));
				scrollObject($(selectObj).parent(),$(selectObj).parent().find("ul"),$(selectObj));
			}
			return false;
		});
		$("*").mouseup(function(e){
			selectObj = null;
			$("body").css("-moz-user-select","auto");
			$("body").css("-khtml-user-select","auto");
			$("body").css("-webkit-user-select","auto");
		});
		$('.bt_inner').mousewheel(function(event, mov){
			wheelObject(this,mov);
			return false;
		});
	}else{
		$(".btn_slider").css("visibility","hidden");
	}
	if($(".fb_inner").find("ul").height() > $(".bt_inner").height() - 45){
		$('.fb_inner').mousewheel(function(event, mov){
			wheelObject(this,mov);
			return false;
		});
	}else{
		$(".fb_slider").css("visibility","hidden");
	}
	
	$(".deco_title").css("display","block");
	
	function wheelObject(obj,mov){
		var v = $(obj).height() / 20;
		var move = parseFloat($(obj).find(".slider").css("top").replace('px',''));
		if (mov > 0) move-=v;
		else if (mov < 0) move+=v;
		
		scrollBar($(obj).find(".slider"),move);
		scrollObject($(obj),$(obj).find("ul"),$(obj).find(".slider"));
	}
	function scrollBar(slider,move){
		var maxy = $(slider).parent().height() - 45;
		if(move < 1) $(slider).css("top","1px");
		else if(move > maxy) $(slider).css("top",maxy+"px");
		else $(slider).css("top",move);
	}
	
	function scrollObject(obj,objinner,slider){
		var move_max = $(obj).height() - 45;
		var item_h = $(objinner).height()-move_max;
		var sc_h = $(slider).css("top").replace('px','');
		var sc_y = item_h * ((sc_h-1) / move_max);
		$(objinner).css("top","-"+sc_y+ "px");
	}
	//==========△スクロールバー▲==========
	
	var newsArray = $(".whats_new");
	for(i = 2;i <= $(".whats_new").length;i++){
		$(".whats_new:nth-child("+i+")").css("display","none");
		$(".whats_new:nth-child("+i+") p").css("opacity",0);
	}
	
	timerN = setTimeout("changeNews1()",2000);
	
	for(i = 1;i <= $(".imgover").length;i++){
		$(".imgover:nth-child("+i+")").mouseover(function(e){
			if($(this).find("a").find("img").attr("src").indexOf("_se") == -1){
				$(this).find("a").find("img").css("visibility","hidden");
			}
		});
		$(".imgover:nth-child("+i+")").mouseout(function(e){
			$(this).find("a").find("img").css("visibility","visible");
		});
	}
	for(i = 1;i <= $(".naviover").length;i++){
		$(".naviover:nth-child("+i+")").mouseover(function(e){
			$(this).find("a").find("img").css("visibility","hidden");
		});
		$(".naviover:nth-child("+i+")").mouseout(function(e){
			$(this).find("a").find("img").css("visibility","visible");
		});
	}
	for(i = 1;i <= $(".overanimate").length;i++){
		$(".overanimate:nth-child("+i+")").mouseover(function(e){
			$(this).animate({opacity:0.8},200);
		});
		$(".overanimate:nth-child("+i+")").mouseout(function(e){
			$(this).animate({opacity:1},200);
		});
	}
	
	var sns_flg = true;
	$(".top_sns_inner").click(function(e){
		$(".top_sns_inner").stop();
		if(sns_flg){
			sns_flg = false;
			$(".sns_close").css("visibility","hidden");
			$(".top_sns_inner").animate({right:"0px"},500);
		}else{
			sns_flg = true;
			$(".sns_close").css("visibility","visible");
			$(".top_sns_inner").animate({right:"-305px"},500);
		}
	});
	$("#overlay").click(function(e){
		clearTimeout(timerLB);
		$("#lightbox").stop();
		$("#overlay").stop();
		$("#overlay").css("display","none");
		$("#lightbox").css("display","none");
	});
	$(".top_right").click(function(e){
		clearTimeout(timerLB);
		$("#lightbox").stop();
		$("#overlay").stop();
		$("#overlay").css("display","none");
		$("#lightbox").css("display","none");
	});
	
	
});

var news_index = 1;
var news_flg = 0;
function changeNews1(){
	$(".whats_new:nth-child("+news_index+") p").stop();
	clearTimeout(timerN);
	if(news_flg == 0){
		var slidearea = $(".whats_new:nth-child("+news_index+") p span").width() - $(".whats_new:nth-child("+news_index+") p").width() + 10;
		if(slidearea > 0){
			$(".whats_new:nth-child("+news_index+") p span").animate({ marginLeft:"-" + slidearea + "px"},slidearea*10);
			timerN = setTimeout("changeNews2()",slidearea*11 + 1000);
		}else{
			timerN = setTimeout("changeNews2()",4000);
		}
		news_flg = 1;
	}else{
		
	}
}
function changeNews2(){
	clearTimeout(timerN);
	$(".whats_new:nth-child("+news_index+") p span").stop();
	if(news_flg == 1){
		$(".whats_new:nth-child("+news_index+") p").animate({ opacity:0},1000);
		timerN = setTimeout("changeNews3()",1500);
		news_flg = 2;
	}else{
		
	}
}
function changeNews3(){
	$(".whats_new:nth-child("+news_index+") p").stop();
	clearTimeout(timerN);
	if(news_flg == 2){
		$(".whats_new:nth-child("+news_index+")").css("display","none");
		$(".whats_new:nth-child("+news_index+") p span").css("marginLeft","0px");
		news_index++;
		if(news_index > $(".whats_new").length) news_index = 1;
		$(".whats_new:nth-child("+news_index+")").css("display","block");
		$(".whats_new:nth-child("+news_index+") p").animate({ opacity:1},1000);
		timerN = setTimeout("changeNews1()",2500);
		news_flg = 0;
	}else{
		
	}
}
var timerLB;
function showLightBox(path,date,info1,info2,info3,url){
	clearTimeout(timerLB);
	timerLB =  setTimeout("showLightBox2()",500);
	$("#lightbox img").attr("src", path);
	$(".lb_text h3").html(info2);
	$(".lb_text p").html(info3);
	if(url){
		$(".lb_text h2").html('<a href="' + url + '">' + info1 + "</a><br /><p>" + date + "</p>");
	}else{
		$(".lb_text h2").html(info1 + "<br /><p>" + date + "</p>");
	}
	$("#overlay").css("width",$("body").width() + "px");
	$("#overlay").css("height",$("body").height() + "px");
	$("#overlay").css("display","block");
	$("#overlay").css("opacity","0");
	$("#overlay").animate({opacity:0.8},500);
	
	if (typeof document.documentElement.style.msInterpolationMode != "undefined") {
		//$("#lightbox").css("opacity","0");
	}else{
		$("#lightbox").css("opacity","0");
	}
	$("#lightbox").css("top",($(document).scrollTop() + 100) + "px");
}

function showLightBox2(){
	$("#lightbox").css("display","block");
	$(".lb_text").css("width",$("#lightbox").find("img").width() + "px");
	var w = $("body").width() / 2 - $("#lightbox").width() / 2;
	if(w < 300) w = 300;
	$("#lightbox").css("left",w + "px");
	if (typeof document.documentElement.style.msInterpolationMode != "undefined") {
  // IE 7 or newer
		//$("#lightbox").css("opacity","1");
	} else {
	  // IE 6 or older, Gecko, Opera, etc.
		$("#lightbox").animate({opacity:1},300);
	}
}
