// JavaScript Document

function init(){
	marginX=[15,15,15,40,30,15];
	btn_flag=true;
	


	setting("#slide1>div",marginX[0]);
	setting("#slide2>div",marginX[1]);
	setting("#slide3>div",marginX[2]);
	setting("#slide4>li",marginX[3]);
	setting("#slide6>div",marginX[5]);
	setting2("#slide7>div",marginX[5]);
	settingSlide5();
	
	
	$("#slide-btn-left1").click(function(){slideRight("#slide1>div",marginX[0])});
	$("#slide-btn-left2").click(function(){slideRight("#slide2>div",marginX[1])});
	$("#slide-btn-left3").click(function(){slideRight("#slide3>div",marginX[2])});
	$("#slide-btn-left4").click(function(){slideRight("#slide4>li",marginX[3])});
	$("#slide-btn-left5").click(function(){slideRight("#slide5>dl",marginX[4])});
	$("#slide-btn-left6").click(function(){slideRight("#slide6>div",marginX[5])});
	$("#slide-btn-left7").click(function(){slideRight("#slide7>div",marginX[5])});

	$("#slide-btn-right1").click(function(){slideLeft("#slide1>div",marginX[0])});
	$("#slide-btn-right2").click(function(){slideLeft("#slide2>div",marginX[1])});
	$("#slide-btn-right3").click(function(){slideLeft("#slide3>div",marginX[2])});
	$("#slide-btn-right4").click(function(){slideLeft("#slide4>li",marginX[3])});
	$("#slide-btn-right5").click(function(){slideLeft("#slide5>dl",marginX[4])});
	$("#slide-btn-right6").click(function(){slideLeft("#slide6>div",marginX[5])});
	$("#slide-btn-right7").click(function(){slideLeft("#slide7>div",marginX[5])});

	$("#slide-btn-left1").mouseover(function(){$(this).css("cursor","pointer")});
	$("#slide-btn-left2").mouseover(function(){$(this).css("cursor","pointer")});
	$("#slide-btn-left3").mouseover(function(){$(this).css("cursor","pointer")});
	$("#slide-btn-left4").mouseover(function(){$(this).css("cursor","pointer")});
	$("#slide-btn-left5").mouseover(function(){$(this).css("cursor","pointer")});
	$("#slide-btn-left6").mouseover(function(){$(this).css("cursor","pointer")});
	$("#slide-btn-left7").mouseover(function(){$(this).css("cursor","pointer")});
	
	$("#slide-btn-right1").mouseover(function(){$(this).css("cursor","pointer")});
	$("#slide-btn-right2").mouseover(function(){$(this).css("cursor","pointer")});
	$("#slide-btn-right3").mouseover(function(){$(this).css("cursor","pointer")});
	$("#slide-btn-right4").mouseover(function(){$(this).css("cursor","pointer")});
	$("#slide-btn-right5").mouseover(function(){$(this).css("cursor","pointer")});
	$("#slide-btn-right6").mouseover(function(){$(this).css("cursor","pointer")});
	$("#slide-btn-right7").mouseover(function(){$(this).css("cursor","pointer")});
	
}




function slideLeft(obj,marginX){
	if(btn_flag){
		btn_flag=false;
		var w=$(obj).first().outerWidth()+marginX;
		var minx=0;
		var maxx=$(".slide-box1c").width();
		
		var minobjx=0;
		var maxobjx=0;
		
		var minobj,maxobj
		

		$(obj).each(function(){
							 if($(this).position().left<=minobjx){
								 minobj=$(this);
								 minobjx=$(this).position().left;
								
							 }
							 if($(this).position().left>=maxobjx){
								 maxobj=$(this);
								 maxobjx=$(this).position().left;
								
							 }
							});

		if(maxobjx>maxx || minobjx<minx){
			if(maxobjx<=maxx){
				minobj.css("left",maxobjx+w);
			}
			
			$(obj).each(function(i){
						 x=$(this).position().left-w;
						 $(this).animate(
										 {"left":x},
										 600,
										 function(){				
											$(minobj).css("left",maxobjx);
											if(i>=$(obj).length-1){
												btn_flag=true;
											}
										 }
										 )
						 })
				
			
		}else{
			btn_flag=true;
		}
		
	}
}

function slideRight(obj,marginX){
	if(btn_flag){
		btn_flag=false;
		var w=$(obj).first().outerWidth()+marginX;
		var minx=0;
		var maxx=$(".slide-box1c").width();
		
		var minobjx=0;
		var maxobjx=0;
		
		var minobj,maxobj

		$(obj).each(function(){
							 if($(this).position().left<=minobjx){
								 minobj=$(this);
								 minobjx=$(this).position().left;
								
							 }
							 if($(this).position().left>=maxobjx){
								 maxobj=$(this);
								 maxobjx=$(this).position().left;
								
							 }
							});

		if(maxobjx>maxx || minobjx<minx){
			
			if(minobjx<=minx){
				maxobj.css("left",minobjx-w);
			}
			
			$(obj).each(function(i){
						 x=$(this).position().left+w;
						 $(this).animate(
										 {"left":x},
										 600,
										 function(){				
											
											if(i>=$(obj).length-1){
												btn_flag=true;
											}
										 }
										 )
						 })
				
			
		}else{
			btn_flag=true;
		}
		
	}
}

function setting(obj,marginX){
	var w=0
	var h=0;
	var sw=0;
	
	$(obj).each(function(){
						 var w1=$(this).outerWidth()+marginX;
						 var h1=$(this).outerHeight(true);				 
						 sw+=w1
						 if( w<w1) {
							 w=w1;
						 }
						 if( h<h1) {
						 	h=h1;
						 }
						 
						 })
	
	$(obj).parent().css("position","relative");
	$(obj).parent().width(sw);
	$(obj).parent().height(h+5);
	$(obj).each(function(i){
			   $(this).css("position","absolute");
			   $(this).css("left",w*i);
			   });

}

function setting2(obj,marginX){
	var w=0;
	var h=0;
	var h_inside=0;
	var sw=0;

	$(obj).each(function(){
						 var w1=$(this).outerWidth()+marginX;
						 var h1=$(this).outerHeight(true);		 
						 var h1_inside=$(this).height();
						 
						 sw+=w1
						 if( w<w1) {
							 w=w1;
						 }
						 if( h<h1) {
						 	h=h1;
						 }
						 
						 if( h_inside<h1_inside) {
						 	h_inside=h1_inside;
						 }
						 
						 
						 })
	
	
	$(obj).parent().css("position","relative");
	$(obj).parent().width(sw);
	$(obj).parent().height(h);
	
	$(obj).each(function(i){
			   $(this).css("position","absolute");
			   $(this).css("left",w*i);
			   $(this).height(h_inside);
			   });
	$("#slide-btn-right7").css("top",h/2-15);
	$("#slide-btn-left7").css("top",h/2-15);

}

function settingSlide5(){
	
	var w=0;
	var h=0;
	var imgh=0;
	var sw=0;
	var dth=0;
	var margin=marginX[4];
	
	
	//タイトルの高さを揃える
	$("#slide5 dt").each(function(){
								   var dth1=$(this).height();
								   if(dth1>dth){
									   dth=dth1;
								   }
								  })
	$("#slide5 dt").height(dth);
	
	
	//画像ブロックの高さを揃える
	$("#slide5 .slide-img1").each(function(){
								   var imgh1=$(this).height();
								   if(imgh1>imgh){
									   imgh=imgh1;
								   }
								  })
	$("#slide5 .slide-img1").height(imgh);
	
	
	//dlブロックを配置
	$("#slide5>dl").each(function(){
						 var w1=$(this).outerWidth()+margin;
						 var h1=$(this).outerHeight(true);		 
						 sw+=w1
						 if( w<w1) {
							 w=w1;
						 }
						 if( h<h1) {
						 	h=h1;
						 }					 
					})
	
	$("#slide5").css("position","relative");
	$("#slide5").width(sw);
	$("#slide5").height(h);
	
	$("#slide5>dl").each(function(i){
			   $(this).css("position","absolute");
			   $(this).css("left",w*i);
			   });
	$("#slide-btn-right5").css("top",h/2-15);
	$("#slide-btn-left5").css("top",h/2-15);
	
	
	
	
}






if(document.all){
	window.attachEvent("onload",init);
}else{
	window.addEventListener("load",init,false);
}
