/************************************************************
* portfolio.js - 詳細画面の表示用
* 
* 株式会社たき工房 media extension | http://www.mex-net.jp/
************************************************************/

var timerID = 0;

function PortForioDetail(){
			
	//トップのサムネイルをクリック
	$("#PortForio ol > li a").live("click",function(){
		//ポートフォリオの詳細画面を表示
		$($(this).attr("href")).addClass('show');
		$("#PortForioDetail , #PortForioDetail > div.show").fadeIn("slow");
		
		//スライドするボックスの幅を画像の数に合わせて設定
		var thumbImgNum = $("div.show").find("img.pic").length/2;
		var obj = $("div.show").find("div.panelContainer");
		var imgW = $(obj).find("img").width();
		$(obj).css({
			"left":"0px",
			"width":imgW*thumbImgNum +"px"
		});
		
		// ウィンドウリサイズしたらleftを「0」に
		$(window).resize(function () {
			clearInterval(timerID);
			// ダイアログボックスが表示されている場合のみ実行
			i = 0;
			$("div.show").find("div.panelContainer").stop().animate({ "left":"0"});
			var HEIGHT = $(window).height();
			$("#PortForioDetail").height(HEIGHT+"px");
		});
		buttonAction();
		showThumb();
		slideShow();
		return false;
	});
}

// 詳細のボタンアクション
function buttonAction(){
	// 閉じるボタン
	$("#PortForio .closeBtn").click(function(){
		$("#PortForioDetail , #PortForioDetail > div.show").fadeOut("slow");
		$("#PortForioDetail > div.show").removeClass("show");
		clearInterval(timerID);
	});
	
	// NEXT/PREVボタン
	$(".prevBtn a , .nextBtn a").live("click", function(){
		//前後の詳細画面を表示
		$("#PortForioDetail > div.show").hide().removeClass('show');
		$($(this).attr("href")).addClass('show');
		$("#PortForioDetail , #PortForioDetail > div.show").fadeIn("slow");
		clearInterval(timerID);
		slideShow();
		
		//スライドするボックスの幅を画像の数に合わせて設定
		var thumbImgNum = $("div.show").find("img.pic").length/2;
		$("div.show").find("div.panelContainer").css({
			"left":"0",
			"width":600*thumbImgNum +"px"
		});
	});
		
	//PREVボタン/NEXTボタン 非表示
	$("li.prevBtn").first().hide();
	$("li.nextBtn").last().hide();
}

//5秒ごとにスライド
function slideShow(){
	timerID = setInterval("slideThumb()", 5000);
}
//スライドの設定
function slideThumb(){
	var obj = $("div.show").find("div.panelContainer");
	
	var posL = $(obj).css("left").split("px");
	var num = Number(posL[0]);
	var imgW = $(obj).find("img").width();
	var imgLen = $(obj).find("img").length;
	var maxL = imgW*imgLen*-1;
	
	if(num > maxL+imgW){
		$(obj).animate({"left":num-imgW+"px"},1000);
	}else{
		$(obj).animate({"left":"0px"},1000);
	}
}

//サムネイルをクリック
function showThumb(){
	$("div.panel a").live("click",function(){
		var anchor = $(this).attr("href").split("_");
		var anchorNum = anchor[1];
		var thumW = $($(this).attr("href")).width();
		$("div.panelContainer").animate({"left":"-" + thumW*anchorNum},1000);
		clearInterval(timerID);
		slideShow();
		return false;
	});
}



//マルチタッチ
/*
$(function() {
	var box = $("#PortForioDetail .descriptBox")[0];
	box.addEventListener("touchstart", touchHandler, false);
	box.addEventListener("touchmove", touchHandler, false);
	box.addEventListener("touchend", touchHandler, false);
});

function touchHandler(e) {
	e.preventDefault();
	var touch = e.touches[0];
	if (e.type == "touchstart") {
		startX = touch.pageX;
	} else if (e.type == "touchmove") {
		diffX = touch.pageX - startX;
	} else if (e.type == "touchend") {
		if (diffX > 100) {
			alert("右方向へフリック！");
		} else if (diffX < -100) {
			alert("左方向へフリック！");
		}
	}
}
*/
