var y = 0;

function showContents() {
	var h = $(window).height();
	$("#main").fadeIn(3000);
	$("#main").append("<div id='slide'></div>");
	var n = $("#pattern li").size();
	var ptnHeight = n*166;
	var numberPtn = Math.floor(h/166);
	var maxHeight = (numberPtn*166 - ptnHeight);
	$("#slide").slider({
		animate:true,
		max:300,
		min:maxHeight,
		orientation:"vertical",
		value:300,
		slide:function(event,ui){
			$("#pattern").css("top",ui.value);
		}
	});		
	$("#footer").fadeIn(4000);
}

function play() {
	var w = $(window).width();
	var h = $(window).height();
	$("#ex_win").css("display","none").css("visibility","visible");
	$("#ex_tlt").css("display","none").css("visibility","visible");
	//$("#ex_win").width(w).height(h).css("overflow","hidden");
	$("#ex_tlt").width(w);
	$("#ex_win").fadeIn(1200,showTlt);
}
function showTlt() {
	$("#ex_tlt").show("drop",{direction:"right"},700);
}
function end() {
	$("#ex_win,#ex_tlt").remove();
	$("#ex_bg").css("display","none");
}
function endAbout() {
	$("#about").css("display","none");
}
function endLicense() {
	$("#licence").css("display","none");
}
function endContact() {
	$("#contact").css("display","none");
}
  
$(function() {
	var w = $(window).width();
	var h = $(window).height();
	var ptnW = (w - 950)/2;
	var ptnPos = Math.floor(ptnW);
	//$("#wrapper").height(h);
	$("#header").width(w);
	//$("#main").height(h).css("overflow","hidden").css("right",ptnPos+"px");
	$("#wrapper").fadeIn(2000);
	$("#header").fadeIn(2200,showContents);
	$("#about,#license,#contact").width(w);
	$("#about,#license,#contact").css("opacity",0.9);
	//スクロールに応じて背景を移動
	$(window).scroll(function(){
		var y1 = document.documentElement.scrollTop;
		var y2 = document.body.scrollTop;
		if (y1>y2) {y=y1} else {y=y2}
		$("#ex_bg").css("top",y+"px");
	});
	//サムネールがクリックされたら
	$("#n1 a").click(function(){
		$("#license").fadeOut(500,endLicense);
		$("#contact").fadeOut(500,endContact);
		$("#about").show("drop",{direction:"left"},1000);
		return false;
	});
	$("#n2 a").click(function(){
		$("#about").fadeOut(500,endAbout);
		$("#contact").fadeOut(500,endContact);
		$("#license").show("drop",{direction:"left"},1000);
		return false;
	});
	$("#n3 a").click(function(){
		$("#about").fadeOut(500,endAbout);
		$("#license").fadeOut(500,endLicense);
		$("#contact").show("drop",{direction:"left"},1000);
		return false;
	});
	//サムネールがクリックされたら
	$(".thum2 a.left,p.expand a").click(function(){
		$("#ex_bg").height(h);
		var imgName =  $(this).attr("href");
		var imgTitle =  $(this).attr("title");
		$("#ex_bg").append("<div id='ex_win'></div>");
		$("#ex_win").css("background-image","url("+imgName+")");
		$("#ex_win").append("<div id='ex_tlt' class='clearfix'><h3>"+imgTitle+"</h3><p id='ex_close'>Close</p></div>");
		$("#ex_tlt,#ex_win").css("display","none").css("visibility","visible");
		$("#ex_bg").fadeIn(1000,play);
		return false;
	});
	//closeがクリックされたら
	$("#ex_close,body").click(function(){
		$("#ex_win,#ex_tlt").fadeOut(500,end);
	});
	$("#about,body").click(function(){
		$("#about").fadeOut(500,endAbout);
	});
	$("#license,body").click(function(){
		$("#license").fadeOut(500,endLicense);
	});
	$("#contact,body").click(function(){
		$("#contact").fadeOut(500,endContact);
	});
	//$("#pattern2").jScrollPane();
});
