var flag=true;
var comit=false;
var prev_page=document.referrer.split("?");
var current_page=location.href.split("?");
if(prev_page[0]==current_page[0])flag=true; else flag=false;
/* トップロゴ　*/
jQuery(function($){
	$("body#siteTop h1").fadeIn(3000);
	$("body#siteTop h1").fadeOut(2000);
});

function changeSet() {
	timerID = setTimeout("changeCategory()", 5000);
}

function changeCategory() {
	location.href = "/wp/archives/category/paper/";
}

/* カテゴリ一覧 li 追加　*/
jQuery(function($){
	var rNavSize = $("body#workCategory #rNav a").size();
	i = 0;
	while (i < rNavSize) {
		var rNavSelector = "body#workCategory #rNav a:nth-child(" + (i+1) +")";
		var rNavData = $(rNavSelector).html();
		if(rNavData == "&gt;&gt;"){
			$(rNavSelector).wrap($("<li id='prev'></li>"));
		} else {
			$(rNavSelector).wrap($("<li id='next'></li>"));
		}
    	i = i + 1;
	}
});

/* ページ開いた時の処理　*/
jQuery(function($){

	//$("div#content").fadeIn(4000);
	var bodyID=$("body").attr("id");
	if(bodyID=="workCategory" || bodyID=="about"){
		$("div#content").css("display","block").css("marginTop","-1120px");
		var openning=function(){
			clearInterval(openningSIV);
			$("div#content").animate({marginTop:"0px"},{duration:2000,easing:"easeOutExpo"});
		}
		var openningSIV=setInterval(openning,1000);
	}else{
		$("div#content").css("display","block");
	}

	if(flag){
		$("body#workDetail .workBox,body#workDetail #workInfo").css("display","block");
	}else{
		$("body#workDetail .workBox,body#workDetail #workInfo").css("display","none").css("marginRight","138px");
		$("body#workDetail p.btnInfo").css("display","none");
	}

	var thisNum = location.href.split("?");
	$("ul#largeImage li:nth-child(1)").css("display","block");
	if(thisNum[1] != undefined){
		var thisSelector = "ul#largeImage li:nth-child(" + thisNum[1] +")";
		$("ul#largeImage li:nth-child(1)").css("display","none");
		$(thisSelector).css("display","block");
	};

	var int=function(){
		clearInterval(intSIV);

		$("ul#largeImage li").animate(
			{marginTop: '0px'},
			{duration:1500 ,easing:"easeOutExpo",complete:function(){
				comit=true;
				$("body#workDetail .workBox").css("display","block");
				$("body#workDetail .workBox,body#workDetail #workInfo").animate(
					{marginRight:"0px"},{duration:1500,easing:"easeInOutExpo"/*,complete:function(){$("body#workDetail #workInfo").css("display","none");}*/}
				);
				$("body#workDetail p.btnInfo").fadeIn(500);
			}});
	}
	var intSIV=setInterval(int,1000);

//	if(history.back())location.reload();
});


/* 詳細ページ　スライド開閉　*/
jQuery(function($){
	var open=false;
	$("p.btnInfo").click(function(){
		if(!open){
			open=true;
			$("p.btnInfo a").empty();
			$("p.btnInfo a").html("BACk").css("backgroundImage","url(http://kotenhits.com/common/img/icon_arrow_right.gif)");
			$("div#workInfo").css("display","block");
			$("div#workInfo").stop(true).animate({ right: 138 } ,{duration: 500 ,easing: "easeInOutCubic"});
			return false;
		}else{
			open=false;
			$("p.btnInfo a").empty();
			$("p.btnInfo a").html("CREDIT").css("backgroundImage","url(http://kotenhits.com/common/img/icon_arrow_left.gif)");
			$("div#workInfo").css("display","block").stop(true).delay( 300 ).animate({ right: -80 } , 500 , "easeInOutCubic");
			return false;
		}
	});
/*
	$("p.infoClose").click(function(){
		$("div#workInfo").css("display","block").stop(true).delay( 300 ).animate({ right: -80 } , 500 , "easeInOutCubic");
		return false;
	});*/
});

/* リンク時の演出　*/
jQuery(function($){
	$("ul#gNav li a,ul#siteNav li a,ul#rNav li a,p.infoClose a,p.btnInfo a").hover(function(){
		$(this).stop(true, true).animate({ marginTop: "-3px" , borderWidth: "1px" , paddingBottom: "2px"}, 250 ,"linear");
	}, function(e){
		$(this).stop(true, true).animate({ marginTop: "0px", borderWidth: "0px" , paddingBottom: "0px"}, 250 ,"linear");
	});
	$("ul#rNav li a").click(function(){

		if($("body").attr("id")!="workCategory"){
			$("body#workDetail p.btnInfo").fadeOut("slow");
			if($("div#workInfo").css("right").replace("px","")-0>-80 && comit==true){
				$("div#workInfo").css("display","block").stop(true).animate({ right: -80 } ,
						{duration: 150 ,easing: "easeInOutCubic",complete:function(){$("body#workDetail #workInfo").css("display","none");}});
			}else{
				$("body#workDetail #workInfo").css("display","none");
			}

			var rNavthislink=$(this).attr("original");
			$("body#workDetail ul#largeImage li,body#workDetail .workBoxWrapper,body#workDetail #workInfo").animate({marginTop:$("body").height()+100}, {easing:"easeInExpo",duration:1000,
				complete:function(){
				$("body#workDetail #workInfo").css("display","none");
					location.href = rNavthislink + "?1";
					return false;
				}
			});
		}else{
			var gNavthislink=$(this).attr("original");
			$("#content").stop(false,false).animate({paddingTop:$("body").height()+100}, {easing:"easeInExpo",duration:1000,
				complete:function(){
				//$("body#workDetail #workInfo").css("display","none");
					location.href = gNavthislink;
					return false;
				}
			});
		}
	});
	$("ul#gNav li a,ul#siteNav li a").click(function(){
		var gNavthislink=$(this).attr("original");
		$("#content").stop(false,false).animate({paddingTop:$("body").height()+100}, {easing:"easeInExpo",duration:1000,
			complete:function(){
			$("body#workDetail #workInfo").css("display","none");
				location.href = gNavthislink;
				return false;
			}
		});
	});
});


/* カテゴリページからの遷移時　*/
jQuery(function($){

	$("body#workCategory ul.thumbList li a").click(function () {
		var elm=this;
		var detailLink =$(this).attr("original");
		$("body").css("overflow","hidden");
		$("#content").stop(false,false).animate({paddingTop:$("body").height()+100}, {easing:"easeInExpo",duration:1000,complete:function(){

			var searchSelecter = "div#" + $(elm).parent().parent().parent().attr("id") + " ul.thumbList li a";
	  		var index = $(searchSelecter).index(elm);

			location.href = detailLink + "?" + (index + 1);
			var wait=function(){
				clearInterval(waitSIV);
				$("#content").css({paddingTop:"195px"});
			}
			var waitSIV=setInterval(wait,1000);
			return false;

		}});
	});
});

/* 詳細ページ大きい画像からの遷移時　*/
jQuery(function($){
	$("body#workDetail ul#largeImage li").click(function () {
		if($("div#workInfo").css("right").replace("px","")-0>-80 && comit==true){
			$("div#workInfo").css("display","block").stop(true).animate({ right: -80 } ,
					{duration: 150 ,easing: "easeInOutCubic",complete:function(){$("body#workDetail #workInfo").css("display","none");}});
		}else{
			$("body#workDetail #workInfo").css("display","none");
		}
		$(this).animate({marginTop:$("body").height()+100}, {easing:"easeInExpo",duration:1000,
			complete:function(){
				var thisNum = location.href.split("?");
		  		var index = $("ul#largeImage li").index(this);
				var n = $("ul#largeImage li").size();
				if ((index + 1) == n) {
					location.href = thisNum[0] + "?1";
				} else {
					location.href = thisNum[0] + "?" + (index + 2);
				}
				return false;
			}
		});

	});
});

/* 詳細ページサムネイルからの遷移時　*/
jQuery(function($){

	$("body#workDetail ul.thumbList li").click(function () {
		if($("div#workInfo").css("right").replace("px","")-0>-80 && comit==true){
			$("div#workInfo").css("display","block").stop(true).animate({ right: -80 } ,
					{duration: 150 ,easing: "easeInOutCubic",complete:function(){$("body#workDetail #workInfo").css("display","none");}});
		}else{
			$("body#workDetail #workInfo").css("display","none");
		}
		 var elmDetailthis=this;
		$("body#workDetail ul#largeImage li").animate({marginTop:$("body").height()+100}, {easing:"easeInExpo",duration:1000,
			complete:function(){

				var thisNum = location.href.split("?");
		  		var index = $("ul.thumbList li").index(elmDetailthis);
				location.href = thisNum[0] + "?" + (index + 1);
				return false;
			}
		});
	});
});

/* サムネイル透過 */
jQuery(function($){
	//$("body").prepend("<span id='dump' style=\"font-size:20px\"></span>");
	$(".workBox").css("overflow","hidden");
	var workBox=$(".workBox .thumbList");
	workBox.css("background","url(http://kotenhits.com/common/js/pixel_trans.gif)");
	var lock=false;
	var prarentID;

		workBox.mouseenter(function(e){

			if(!lock && prarentID!=$(this).parent().attr("id")){
				prarentID=$(this).parent().attr("id");
				//$("#dump").html();
				lock=true;

				var centerPos=(jQuery("body").width()-956)/2;

				var workBoxID=prarentID.replace("workBox","")-0-1;
				var workBoxW=$(this).width();
				var workBoxPos=(workBoxID*workBoxW)+(workBoxID*($(this).parent().css("marginRight").replace("px","")-0));
				var currentWorkBoxPos=centerPos+workBoxPos;
				var margin;
				if(e.pageX<currentWorkBoxPos+(workBoxW/2) && e.pageX>currentWorkBoxPos){
					direction="l";

				}
				if(e.pageX<currentWorkBoxPos+workBoxW && e.pageX>currentWorkBoxPos+(workBoxW/2)){
					direction="r";

				}
				if(direction=="l") margin="-128px";else  margin="128px";

				var elm=$(this).find("li");
				var elmImg=$(this).find("li img");

				if(elm.css("marginLeft")=="0px" && direction){

					direction="";

						elm.css({marginLeft:margin});
						elmImg.css({opacity: 0 });
						elm.stop(true,false).animate({marginLeft:"0px"}, {easing:"easeOutExpo",duration:500});
						elmImg.stop().animate({opacity: 1 }, {easing:"linear",duration:800});

				}
				//$("#dump").html(e.pageX +" "+(currentWorkBoxPos+workBoxW+" "+direction ));

			}
		});
		workBox.mouseout(function(e){
			lock=false;

		});
		$("#header,#area,.workBox h2,.workBox p,.workBox .credit").mouseover(function(e){
			prarentID="";
		});

});

