$(function(){
	/* init */
	var areaCenter = $("#areaCenter");
	var areaLeft = $("#areaLeft");
	var areaRight = $("#areaRight");
	var h = $(document).height();
	var moveLeft = $("#areaLeft .moveBox");
	var moveCenter = $("#areaCenter .moveBox");
	var moveRight = $("#areaRight .moveBox");
	var leftScrlID = setInterval(leftScrl,3500);
	var centerScrlID = setInterval(centerScrl,1500);
	var rightScrlID = setInterval(rightScrl,2500);
	var leftScNum = 1;
	var rightScNum = 1;
	var centerScNum = $(".box",moveCenter).length;
	var imgSize = $(".box p.imgBox img");
	imgSize.attr({width:Math.round(imgSize.width()/1.526), height:Math.round(imgSize.height()/1.52)});
	var parMinW = 225;
	var parMaxW = 325;
	var minW = 214;
	var maxW = 314;
	var minH = 200;
	var maxH = 350;
	var pos = "";
	flg=0;
	leftSt(flg);
	centerSt(flg);
	rightSt(flg);
	

/* left */
	function leftSt(flg){
		i=1;
		if(flg == 0){
			n=1;
		}
		leftBoxlen = $(".box",moveLeft).length;
		if(h+$(".box:first",moveLeft).outerHeight(true)>moveLeft.height()){
			flg=1;
			$(".box:last",moveLeft).after("<div class='leftPost0"+(leftBoxlen+i)+" box'></div>");
			$(".leftPost0"+n).contents().clone().appendTo(".leftPost0"+(leftBoxlen+i));
			n++;
			return leftSt(flg);
		}
		for(c=1; c<=leftBoxlen; c++){
			$(".leftPost0"+c+" .moreNav a").attr("rel",c);
			$(".leftPost0"+c).hover(
			function(){
				var cNum = $(".moreNav a",this).attr("rel");
				defaultHeight = $(".leftPost0"+cNum).innerHeight();
				imgw = $(".leftPost0"+cNum+" p.imgBox img").width();
				imgh = $(".leftPost0"+cNum+" p.imgBox img").height();
				if(defaultHeight > maxH){
					$(".leftPost0"+cNum).stop(true, false).animate({width:maxW, height:defaultHeight});
					$(".leftPost0"+cNum+" .inBox").stop(true, false).animate({width:maxW-8, height:defaultHeight});
					$(".leftPost0"+cNum+" .boxbgL, .leftPost0"+cNum+" .boxbgR").stop(true, false).animate({height:defaultHeight});
				}else{
					$(".leftPost0"+cNum).stop(true, false).animate({width:maxW, height:maxH});
					$(".leftPost0"+cNum+" .inBox").stop(true, false).animate({width:maxW-8, height:maxH});
					$(".leftPost0"+cNum+" .boxbgL, .leftPost0"+cNum+" .boxbgR").stop(true, false).animate({height:maxH});
				}
				$(".leftPost0"+cNum+" .invisibleBox").show("slow");
				$(".leftPost0"+cNum+" p.imgBox img").stop(true,false).animate({width:Math.round(imgw*1.53), height:Math.round(imgh*1.52)});
				$(".leftPost0"+cNum+" .bghead, .leftPost0"+cNum+" .bgfoot").stop(true,false).animate({width:maxW});
				$(".leftPost0"+cNum+" .bgC").stop(true,false).animate({width:maxW-8});
			},
			function(){
				var cNum = $(".moreNav a",this).attr("rel");
				if(defaultHeight > minH){
					$(".leftPost0"+cNum).stop(true, false).animate({width:minW, height:defaultHeight});
					$(".leftPost0"+cNum+" .inBox").stop(true,false).animate({width:minW-8, height:defaultHeight});
					$(".leftPost0"+cNum+" .boxbgL, .leftPost0"+cNum+" .boxbgR").stop(true, false).animate({height:defaultHeight});
				}else{
					$(".leftPost0"+cNum).stop(true, false).animate({width:minW, height:minH});
					$(".leftPost0"+cNum+" .inBox").stop(true,false).animate({width:minW-8, height:minH});
					$(".leftPost0"+cNum+" .boxbgL, .leftPost0"+cNum+" .boxbgR").stop(true, false).animate({height:minH});
				}
				$(".leftPost0"+cNum+" .invisibleBox").hide("slow");
				$(".leftPost0"+cNum+" p.imgBox img").stop(true,false).animate({width:imgw, height:imgh});
				$(".leftPost0"+cNum+" .bghead, .leftPost0"+cNum+" .bgfoot").stop(true,false).animate({width:minW});
				$(".leftPost0"+cNum+" .bgC").stop(true,false).animate({width:minW-8});
			});
		}
	}

	function leftScrl(){
		leftBoxlen = $(".box",moveLeft).length;
		if(leftBoxlen < leftScNum){
			leftScNum = 1;
		}
		defaultHeight = $(".leftPost0"+leftScNum).outerHeight(true);
		$(".leftPost0"+leftScNum).stop(true,false).animate({marginTop:-defaultHeight},{complete:function(){$(this).remove();}});
		$(".leftPost0"+leftScNum).clone().appendTo(moveLeft).hover(
			//縦方向拡大設定
			function(){
				pos=".left";
				cnt = $(".moreNav a",this).attr("rel");
				dh = $(".leftPost0"+cnt).innerHeight();
				imgw = $(".leftPost0"+cnt+" p.imgBox img").width();
				imgh = $(".leftPost0"+cnt+" p.imgBox img").height();
				expan(pos,cnt,dh,imgw,imgh);
			},
			function(){
				pos=".left";
				cnt = $(".moreNav a",this).attr("rel");
				reduc(pos,cnt,dh,imgw,imgh);
			});
		leftScNum++;
	}

/* center */
	function centerSt(flg){
		i=1;
		if(flg == 0){
			n=1;
		}
		cenBoxlen = $(".box",moveCenter).length;
		if(h>moveCenter.height()){
			flg=1;
			$(".box:first",moveCenter).before("<div class='cenPost0"+(cenBoxlen+i)+" box'></div>");
			$(".cenPost0"+n).contents().clone().appendTo(".cenPost0"+(cenBoxlen+i));
			n++;
			return centerSt(flg);
		}
		for(c=1; c<=cenBoxlen; c++){
			$(".cenPost0"+c+" .moreNav a").attr("rel",c);
			$(".cenPost0"+c).hover(
			function(){
				var cNum = $(".moreNav a",this).attr("rel");
				imgw = $(".cenPost0"+cNum+" p.imgBox img").width();
				imgh = $(".cenPost0"+cNum+" p.imgBox img").height();
				defaultHeight = $(".cenPost0"+cNum).innerHeight();
				if(defaultHeight > maxH){
					$(".cenPost0"+cNum).stop(true, false).animate({width:maxW, height:defaultHeight});
					$(".cenPost0"+cNum+" .inBox").stop(true, false).animate({width:maxW-8, height:defaultHeight});
					$(".cenPost0"+cNum+" .boxbgL, .cenPost0"+cNum+" .boxbgR").stop(true, false).animate({height:defaultHeight});
				}else{
					$(".cenPost0"+cNum).stop(true, false).animate({width:maxW, height:maxH});
					$(".cenPost0"+cNum+" .inBox").stop(true, false).animate({width:maxW-8, height:maxH});
					$(".cenPost0"+cNum+" .boxbgL, .cenPost0"+cNum+" .boxbgR").stop(true, false).animate({height:maxH});
				}
				$(".cenPost0"+cNum+" .invisibleBox").show("slow");
				$(".cenPost0"+cNum+" p.imgBox img").stop(true,false).animate({width:Math.round(imgw*1.53), height:Math.round(imgh*1.52)});
				$(".cenPost0"+cNum+" .bghead, .cenPost0"+cNum+" .bgfoot").stop(true,false).animate({width:maxW});
				$(".cenPost0"+cNum+" .bgC").stop(true,false).animate({width:maxW-8});
			},
			function(){
				var cNum = $(".moreNav a",this).attr("rel");
				if(defaultHeight > minH){
					$(".cenPost0"+cNum).stop(true, false).animate({width:minW, height:defaultHeight});
					$(".cenPost0"+cNum+" .inBox").stop(true,false).animate({width:minW-8, height:defaultHeight});
					$(".cenPost0"+cNum+" .boxbgL, .cenPost0"+cNum+" .boxbgR").stop(true, false).animate({height:defaultHeight});
				}else{
					$(".cenPost0"+cNum).stop(true, false).animate({width:minW, height:minH});
					$(".cenPost0"+cNum+" .inBox").stop(true,false).animate({width:minW-8, height:minH});
					$(".cenPost0"+cNum+" .boxbgL, .cenPost0"+cNum+" .boxbgR").stop(true, false).animate({height:minH});
				}
				$(".cenPost0"+cNum+" .invisibleBox").hide("slow");
				$(".cenPost0"+cNum+" p.imgBox img").stop(true,false).animate({width:imgw, height:imgh});
				$(".cenPost0"+cNum+" .bghead, .cenPost0"+cNum+" .bgfoot").stop(true,false).animate({width:minW});
				$(".cenPost0"+cNum+" .bgC").stop(true,false).animate({width:minW-8});
			});
		}
	}

	function centerScrl(){
		if(centerScNum < 1){
			centerScNum = $(".box",moveCenter).length;
		}
		defaultHeight = $(".cenPost0"+centerScNum).innerHeight();
		$(".cenPost0"+centerScNum).clone().prependTo(moveCenter).css({"height":0}).stop(true,false).animate({height:defaultHeight}).hover(
			//縦方向拡大設定
			function(){
				pos=".cen";
				cnt = $(".moreNav a",this).attr("rel");
				dh = $(".cenPost0"+cnt).innerHeight();
				imgw = $(".cenPost0"+cnt+" p.imgBox img").width();
				imgh = $(".cenPost0"+cnt+" p.imgBox img").height();
				expan(pos,cnt,dh,imgw,imgh);
			},
			function(){
				pos=".cen";
				cnt = $(".moreNav a",this).attr("rel");
				reduc(pos,cnt,dh,imgw,imgh);
			});
		$(".cenPost0"+centerScNum+":last").remove();
		centerScNum--;
	}

/* right */
	function rightSt(flg){
		i=1;
		if(flg == 0){
			n=1;
		}
		rightBoxlen = $(".box",moveRight).length;
		if(h+$(".box:first",moveRight).outerHeight()>moveRight.height()){
			flg=1;
			$(".box:last",moveRight).after("<div class='rightPost0"+(rightBoxlen+i)+" box'></div>");
			$(".rightPost0"+n).contents().clone().appendTo(".rightPost0"+(rightBoxlen+i));
			n++;
			return rightSt(flg);
		}
		for(c=1; c<=rightBoxlen; c++){
			$(".rightPost0"+c+" .moreNav a").attr("rel",c);
			$(".rightPost0"+c).hover(
			function(){
				var cNum = $(".moreNav a",this).attr("rel");
				imgw = $(".rightPost0"+cNum+" p.imgBox img").width();
				imgh = $(".rightPost0"+cNum+" p.imgBox img").height();
				defaultHeight = $(".rightPost0"+cNum).innerHeight();
				if(defaultHeight > maxH){
					$(".rightPost0"+cNum).stop(true, false).animate({width:maxW, height:defaultHeight});
					$(".rightPost0"+cNum+" .inBox").stop(true, false).animate({width:maxW-8, height:defaultHeight});
					$(".rightPost0"+cNum+" .boxbgL, .rightPost0"+cNum+" .boxbgR").stop(true, false).animate({height:defaultHeight});
				}else{
					$(".rightPost0"+cNum).stop(true, false).animate({width:maxW, height:maxH});
					$(".rightPost0"+cNum+" .inBox").stop(true, false).animate({width:maxW-8, height:maxH});
					$(".rightPost0"+cNum+" .boxbgL, .rightPost0"+cNum+" .boxbgR").stop(true, false).animate({height:maxH});
				}
				$(".rightPost0"+cNum+" .invisibleBox").show("slow");
				$(".rightPost0"+cNum+" p.imgBox img").stop(true,false).animate({width:Math.round(imgw*1.53), height:Math.round(imgh*1.52)});
				$(".rightPost0"+cNum+" .bghead, .rightPost0"+cNum+" .bgfoot").stop(true,false).animate({width:maxW});
				$(".rightPost0"+cNum+" .bgC").stop(true,false).animate({width:maxW-8});
			},
			function(){
				var cNum = $(".moreNav a",this).attr("rel");
				if(defaultHeight > minH){
					$(".rightPost0"+cNum).stop(true, false).animate({width:minW, height:defaultHeight});
					$(".rightPost0"+cNum+" .inBox").stop(true,false).animate({width:minW-8, height:defaultHeight});
					$(".rightPost0"+cNum+" .boxbgL, .rightPost0"+cNum+" .boxbgR").stop(true, false).animate({height:defaultHeight});
				}else{
					$(".rightPost0"+cNum).stop(true, false).animate({width:minW, height:minH});
					$(".rightPost0"+cNum+" .inBox").stop(true,false).animate({width:minW-8, height:minH});
					$(".rightPost0"+cNum+" .boxbgL, .rightPost0"+cNum+" .boxbgR").stop(true, false).animate({height:minH});
				}
				$(".rightPost0"+cNum+" .invisibleBox").hide("slow");
				$(".rightPost0"+cNum+" p.imgBox img").stop(true,false).animate({width:imgw, height:imgh});
				$(".rightPost0"+cNum+" .bghead, .rightPost0"+cNum+" .bgfoot").stop(true,false).animate({width:minW});
				$(".rightPost0"+cNum+" .bgC").stop(true,false).animate({width:minW-8});
			});
		}
	}
	function rightScrl(){
		rightBoxlen = $(".box",moveRight).length;
		if(rightBoxlen < rightScNum){
			rightScNum = 1;
		}
		defaultHeight = $(".rightPost0"+rightScNum).outerHeight(true);
		$(".rightPost0"+rightScNum).stop(true,false).animate({marginTop:-defaultHeight},{complete:function(){$(this).remove();}});
		$(".rightPost0"+rightScNum).clone().appendTo(moveRight).hover(
			//縦方向拡大設定
			function(){
				pos=".right";
				cnt = $(".moreNav a",this).attr("rel");
				dh = $(".rightPost0"+cnt).innerHeight();
				imgw = $(".rightPost0"+cnt+" p.imgBox img").width();
				imgh = $(".rightPost0"+cnt+" p.imgBox img").height();
				expan(pos,cnt,dh,imgw,imgh);
			},
			function(){
				pos=".right";
				cnt = $(".moreNav a",this).attr("rel");
				reduc(pos,cnt,dh,imgw,imgh);
			});
		rightScNum++;
	}

/* クローン拡大 */
	function expan(pos,cnt,dh,imgw,imgh){
			if(dh > maxH){
				$(pos+"Post0"+cnt).stop(true,false).animate({width:maxW, height:dh});
				$(pos+"Post0"+cnt+" .inBox").stop(true,false).animate({width:maxW-8, height:dh});
				$(pos+"Post0"+cnt+" .boxbgL, "+pos+"Post0"+cnt+" .boxbgR").stop(true, false).animate({height:dh});
			}else{
				$(pos+"Post0"+cnt).stop(true,false).animate({width:maxW, height:maxH});
				$(pos+"Post0"+cnt+" .inBox").stop(true,false).animate({width:maxW-8, height:maxH});
				$(pos+"Post0"+cnt+" .boxbgL, "+pos+"Post0"+cnt+" .boxbgR").stop(true, false).animate({height:maxH});
			}
			$(pos+"Post0"+cnt+" .invisibleBox").show("slow");
			$(pos+"Post0"+cnt+" p.imgBox img").stop(true,false).animate({width:Math.round(imgw*1.53), height:Math.round(imgh*1.52)});
			$(pos+"Post0"+cnt+" .bghead, "+pos+"Post0"+cnt+" .bgfoot").stop(true,false).animate({width:maxW});
			$(pos+"Post0"+cnt+" .bgC").stop(true,false).animate({width:maxW-8});
	}
	function reduc(pos,cnt,dh,imgw,imgh){
			if(dh > minH){
				$(pos+"Post0"+cnt).stop(true,false).animate({width:minW, height:dh});
				$(pos+"Post0"+cnt+" .inBox").stop(true,false).animate({width:minW-8, height:dh});
				$(pos+"Post0"+cnt+" .boxbgL, "+pos+"Post0"+cnt+" .boxbgR").stop(true, false).animate({height:dh});
			}else{
				$(pos+"Post0"+cnt).stop(true,false).animate({width:minW, height:minH});
				$(pos+"Post0"+cnt+" .inBox").stop(true,false).animate({width:minW-8, height:minH});
				$(pos+"Post0"+cnt+" .boxbgL, "+pos+"Post0"+cnt+" .boxbgR").stop(true, false).animate({height:minH});
			}
			$(pos+"Post0"+cnt+" .invisibleBox").hide("slow");
			$(pos+"Post0"+cnt+" p.imgBox img").stop(true,false).animate({width:imgw, height:imgh});
			$(pos+"Post0"+cnt+" .bghead, "+pos+"Post0"+cnt+" .bgfoot").stop(true,false).animate({width:minW});
			$(pos+"Post0"+cnt+" .bgC").stop(true,false).animate({width:minW-8});
	}

/* 横方向に拡大 /*/
	areaLeft.hover(
	function(){
		openPlay();
		areaLeft.stop(true, false).animate({width:parMaxW});
		areaCenter.stop(true,false).animate({left:560});
		areaRight.stop(true,false).animate({left:785});
	},
	function(){
		close(areaLeft);
	});

	areaCenter.hover(
	function(){
		openPlay();
		areaCenter.stop(true,false).animate({left:460, width:parMaxW});
		areaLeft.stop(true,false).animate({width:parMinW});
		areaRight.stop(true,false).animate({left:785});
	},
	function(){
		close(areaCenter);
	});

	areaRight.hover(
	function(){
		openPlay();
		areaRight.stop(true,false).animate({left:685,width:parMaxW});
		areaLeft.stop(true,false).animate({width:parMinW});
		areaCenter.stop(true,false).animate({left:460, width:parMinW});
	},
	function(){
		close(areaRight);
	});

	function openPlay(){
		clearInterval(leftScrlID);
		clearInterval(centerScrlID);
		clearInterval(rightScrlID);
	}
	function close(pos){
		areaLeft.stop(true,false).animate({width:parMinW});
		areaCenter.stop(true,false).animate({left:460, width:parMinW});
		areaRight.stop(true,false).animate({left:685, width:parMinW});
		leftScrlID = setInterval(leftScrl,3500);
		centerScrlID = setInterval(centerScrl,1500);
		rightScrlID = setInterval(rightScrl,2500);
	}
/**/
});

