// JavaScript Document

//▼▼　メインサイズの変更　▼▼
//$(function(){
//	var w = $(window);
//	var height_max = "600px";
//	var height_max_m = -parseInt(height_max)/2 + "px";
//	var height_min = "500px";
//	var height_min_m = -parseInt(height_min)/2 + "px";
//	$("#test").text(w.width()+"*"+w.height());
//	if (parseInt(w.height()) <= parseInt(height_max)) {
//		$("#wrapper").css("height",height_min).css("marginTop",height_min_m);
//		$("article,#side,.inner").css("height",height_min);
//	}
//	w.resize(function(){
//		$("#test").text(w.width()+"*"+w.height());
//		if (parseInt(w.height()) <= parseInt(height_max)) {//height_max以下の時、height_minの高さにする
//			$("#wrapper").css("height",height_min).css("marginTop",height_min_m);
//			$("article,#side,.inner").css("height",height_min);
//		} else {//当てはまらないときheight_maxの高さにする
//			$("#wrapper").css("height",height_max).css("marginTop",height_max_m);
//			$("aritcle,#side,.inner").css("height",height_max);
//		}
//	});
//});

//▼▼　スクロールの効果　▼▼
$(function(){
	var scroll_effect = "easeInOutQuad";
	var scroll_speed = 2000;
	var fadeTo_speed = 500;
	var n;

//	easeInQuad easeOutQuad easeInOutQuad
//	easeInCubic easeOutCubic easeInOutCubic
//	easeInQuart easeOutQuart easeInOutQuart
//	easeInQuint easeOutQuint easeInOutQuint
//	easeInSine easeOutSine easeInOutSine
//	easeInExpo easeOutExpo easeInOutExpo
//	easeInCirc easeOutCirc easeInOutCirc
//	easeInElastic easeOutElastic easeInOutElastic
//	easeInBack easeOutBack easeInOutBack
//	easeInBounce easeOutBounce easeInOutBounce
	//▼▼　上下のスクロール　▼▼
	$("#pagewrap").css("marginTop",-parseInt($("#top").css("top"))+"px");
	$("nav:not('#ssl') a:not(:animated):not([href^='https']),#link_access_map:not(:animated),#logo a:not(:animated)").click(function(){
		if ($(this).attr("class") != "active") {
			n = -parseInt($($(this).attr("href")).css("top"))+"px";
			$("#side").fadeTo(fadeTo_speed,0);
			$("footer").fadeTo(fadeTo_speed,0);
			$(".inner").fadeTo(fadeTo_speed,0,function(){
				$("#pagewrap:not(:animated)").animate({
					marginTop : n
				},scroll_speed,scroll_effect,function(){
					scrollreset();
					$("#side").fadeTo(fadeTo_speed,1);
					$("footer").fadeTo(fadeTo_speed,1);
					$(".inner").fadeTo(fadeTo_speed,1);
				});
			});
			return false;
		}
		return false;
	});
	//▼▼　横スクロール／タブパネルのリセット　▼▼
	function scrollreset(){
		$("#company_info .inner").css("marginLeft","0px");
		$("#philosophy .inner").css("marginLeft","0px");
		$("#creator .inner").css("marginLeft","0px");
		$("ul.tab_g li a").removeClass("selected");
		$("a[href$='#tab_g1']").addClass("selected");
		$("ul.panel_g > li").hide();
		$("#tab_g1").show();
		$("ul.tab_w li a").removeClass("selected");
		$("a[href$='#tab_w1']").addClass("selected");
		$("ul.panel_w > li").hide();
		$("#tab_w1").show();
	}
	//▼▼　会社案内の横スクロール　▼▼
	$("#link_summary a:not(:animated)").click(function(){
		$("#side").fadeTo(fadeTo_speed,0);
		$("footer").fadeTo(fadeTo_speed,0,function(){
			$("#company_info .inner:not(:animated)").animate({
				marginLeft : "-1250px"
			},scroll_speed,scroll_effect,function(){
				$("#side").fadeTo(fadeTo_speed,1);
				$("footer").fadeTo(fadeTo_speed,1);
			});
		});
		return false;
	});
	$("#link_company_info a:not(:animated)").click(function(){
		$("#side").fadeTo(fadeTo_speed,0);
		$("footer").fadeTo(fadeTo_speed,0,function(){
			$("#company_info .inner:not(:animated)").animate({
				marginLeft : "0px"
			},scroll_speed,scroll_effect,function(){
				$("#side").fadeTo(fadeTo_speed,1);
				$("footer").fadeTo(fadeTo_speed,1);
			});
		});
		return false;
	});
	//▼▼　基本理念の横スクロール　▼▼
	$("#link_action a:not(:animated)").click(function(){
		$("#side").fadeTo(fadeTo_speed,0);
		$("footer").fadeTo(fadeTo_speed,0,function(){
			$("#philosophy .inner:not(:animated)").animate({
				marginLeft : "-1250px"
			},scroll_speed,scroll_effect,function(){
				$("#side").fadeTo(fadeTo_speed,1);
				$("footer").fadeTo(fadeTo_speed,1);
			});
		});
		return false;
	});
	$("#link_philosophy a:not(:animated)").click(function(){
		$("#side").fadeTo(fadeTo_speed,0);
		$("footer").fadeTo(fadeTo_speed,0,function(){
			$("#philosophy .inner:not(:animated)").animate({
				marginLeft : "0px"
			},scroll_speed,scroll_effect,function(){
				$("#side").fadeTo(fadeTo_speed,1);
				$("footer").fadeTo(fadeTo_speed,1);
			});
		});
		return false;
	});
	//▼▼　クリエイターの横スクロール　▼▼
	$("#link_omake a:not(:animated)").click(function(){
		$("#side").fadeTo(fadeTo_speed,0);
		$("footer").fadeTo(fadeTo_speed,0,function(){
			$("#creator .inner:not(:animated)").animate({
				marginLeft : "-1250px"
			},scroll_speed,scroll_effect,function(){
				$("#side").fadeTo(fadeTo_speed,1);
				$("footer").fadeTo(fadeTo_speed,1);
			});
		});
		return false;
	});
	$("#link_creator a:not(:animated)").click(function(){
		$("#side").fadeTo(fadeTo_speed,0);
		$("footer").fadeTo(fadeTo_speed,0,function(){
			$("#creator .inner:not(:animated)").animate({
				marginLeft : "0px"
			},scroll_speed,scroll_effect,function(){
				$("#side").fadeTo(fadeTo_speed,1);
				$("footer").fadeTo(fadeTo_speed,1);
			});
		});
		return false;
	});
});

//▼▼　お問い合わせページへ移動　▼▼
//$(function(){
//	$("nav:not('#ssl') a[href^='https']").click(function(){
//		var u = $(this).attr("href");
//		$("body").fadeOut(1000,function(){
//			location.href = u;
//		});
//		return false;
//	});
//});

//▼▼　ナビをクリックした時、aタグにclass="active"を追加　▼▼
$(function(){
	$("nav a").click(function(){
		$("nav a").removeClass("active");
		$(this).addClass("active");
		//$("img",this).attr("src",$("img",this).attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_on$2"));
		//$("img",this).removeClass("rollover");
	});
});

//▼▼　背景を見るボタンをクリックした時の効果　▼▼
//$(function(){
//	var scroll_effect = "easeInOutQuad";
//	var scroll_speed = 2000;
//	var fadeTo_speed = 500;
//	var n;
//	$("#side button").toggle(function(){
//		$("nav").fadeOut(fadeTo_speed);
//		$(".inner").fadeTo(fadeTo_speed,0);
//		$("#side button").text("背景を隠す");
//		//▼▼　マウスホイールでスクロールさせる関数　▼▼
//		$("html,body").mousewheel(function(event, delta) {
//			var s = 50;//スクロールする距離（px）
//			var m = parseInt($("#pagewrap").css("marginTop"));
//			var f = -parseInt($("#creator").css("top"));
//			if (delta > 0) {
//				if (m <= 0) {
//					$("#pagewrap").animate({
//						marginTop : m + s + "px"
//					},0);
//				}
//			} else if (delta < 0) {
//				if (f <= m) {
//					$("#pagewrap").animate({
//						marginTop : m - s + "px"
//					},0);
//				}
//			}
//		});
//	},function(){
//		$("html,body").unbind("mousewheel");
//		n = -parseInt($($(".active").attr("href")).css("top"))+"px";
//		$("#pagewrap:not(:animated)").animate({
//				marginTop : n
//		},scroll_speed,scroll_effect,function(){
//			$("nav").fadeIn(fadeTo_speed);
//			$(".inner").fadeTo(fadeTo_speed,1);
//			$("#side button").text("背景を見る");
//		});
//	});
//});


//▼▼　モーダルウィンドウ　▼▼
$(function(){
    $("#top .inner section dl dd").hide();
    $("body").append("<div id='glayLayer'></div><div id='overLayer'></div>");
    $("#glayLayer").click(function(){
        $(this).fadeOut(1000);
        $("#overLayer").fadeOut(1000);
    });
    $("#top .inner section dl dt").click(function(){
        $("#glayLayer").fadeTo(1000,0.75);
        $("#overLayer").fadeIn(1000).html($("+dd",this).html()).css({
            marginTop:"-"+$("#overLayer").height()/2+"px" , 
            marginLeft:"-"+$("#overLayer").width()/2+"px" 
        });
        return false;
    });
    if($.browser.msie && $.browser.version<7){
        $(window).scroll(function(){
            $("#glayLayer").get(0).style.setExpression("top","$(document).scrollTop()+'px'");
            $("#overLayer").get(0).style.setExpression("top","($(document).scrollTop()+$(window).height()/2)+'px'");
        });
    }
    
});
//▼▼　富士山　▼▼
$(function(){
	$("#fujiyama div").css("display","block");
	$("#fujiyama a").click(function(){
		var x = parseInt($("#fujiyama").css("left"));
		$("#fujiyama div").css("display","block");
		$("#fujiyama")
			.animate({left : x + 3 + "px"},75)
			.animate({left : x + "px"},75)
			.animate({left : x + 3 + "px"},75)
			.animate({left : x + "px"},75)
			.animate({left : x + 3 + "px"},75)
			.animate({left : x + "px"},75)
			.animate({left : x + 3 + "px"},75)
			.animate({left : x + "px"},75)
			.animate({left : x + 3 + "px"},75)
			.animate({left : x + "px"},75,function(){
				$("#fujiyama div").delay(500).slideUp(250);
			});
		return false;
	});
});

//▼▼　雲　▼▼
$(function(){
	var k = $("#kaminari");
	$(k).fadeTo(0,0);
	$("#ame").hide();
	$("#kumo a").click(function(){
		$(k).fadeTo(0,0);
		$("#ame").hide();
		$(k).delay(75).fadeTo(0,1,function(){
			$(k).delay(75).fadeTo(0,0,function(){
				$(k).delay(75).fadeTo(0,1,function(){
					$(k).delay(75).fadeTo(0,0,function(){
						$(k).delay(75).fadeTo(0,1,function(){
							$("#ame").delay(500).slideDown(200);
						});
					});
				});
			});
		});
		return false;
	});
});

//▼▼　クリエイター　▼▼
function ZeroFormat(num, n){// ZeroFormat(1,3) => "001"
	var ret=""+num;
	while(ret.length < n){
		ret = "0" + ret;
	}
	return (ret);
}
$(function(){
	$("#creator_list a").mouseover(function(){
		var mouse = $(this);
		var creator = $(this).attr("href");
		var photo = $("img.parapara",this);
		var c,n;
		var i = 0;
		if (creator == "satoko/"){
			c = "image/creator/satoko/";
			n = 36;
		} else if (creator == "michiko/") {
			c = "image/creator/michiko/";
			n = 27;
		} else if (creator == "takako/") {
			c = "image/creator/takako/";
			n = 22;
		} else if (creator == "yuuki/") {
			c = "image/creator/yuuki/";
			n = 33;
		} else if (creator == "ryohei/") {
			c = "image/creator/ryohei/";
			n = 31;
		}
		var timerID = setInterval(function(){
			dance = c + ZeroFormat(i,3) + ".jpg";
			photo.attr("src",dance);
			i++;
			if (i>n) {
				i=0;
			}
			mouse.mouseout(function(){
				clearInterval(timerID);
			});
		},300);
	});
});
$(function(){
	$("#all,#exile").mouseover(function(){
		var creator = $(this);
		var mouse = $(this);
		var c,n;
		var i = 0;
		if (creator.attr("id") == "all"){
			c = "image/creator/all/";
			n = 25;
		} else if (creator.attr("id") == "exile") {
			c = "image/creator/exile/";
			n = 37;
		}
		var timerID = setInterval(function(){
			dance = c + ZeroFormat(i,3) + ".jpg";
			creator.attr("src",dance);
			i++;
			if (i>n) {
				i=0;
			}
			mouse.mouseout(function(){
				clearInterval(timerID);
			});
		},300);
	});
});
//▼▼　works_graphic タブパネル　▼▼
$(function(){
	$("ul.panel_g > li:not("+$("ul.tab_g li a.selected").attr("href")+")").hide();
	$("ul.tab_g li a").click(function(){
		$("ul.tab_g li a").removeClass("selected");
		$(this).addClass("selected");
		$("ul.panel_g>li").hide();
		$($(this).attr("href")).slideDown("fast");
		return false;
	});
});
//▼▼　works_web タブパネル　▼▼
$(function(){
	$("ul.panel_w > li:not("+$("ul.tab_w li a.selected").attr("href")+")").hide();
	$("ul.tab_w li a").click(function(){
		$("ul.tab_w li a").removeClass("selected");
		$(this).addClass("selected");
		$("ul.panel_w>li").hide();
		$($(this).attr("href")).slideDown("fast");
		return false;
	});
});