var s_img_w =1400;
var s_img_h =460;
var stage_flg=1;
var now_move=0;
var timer="";
var wait_time=6000;
var move_speed=1500;

$(function(){
		   stage_size();
		   $("#img_stage_1,#img_stage_2").css({"opacity":0,"left":870});
		   $("#img_stage_1").css_animate({"opacity":1,"left":5},move_speed,"easeInOutCubic");
		   
		   $(window).resize(function(){stage_size();});
		   
		   timer = setTimeout("rotation_img('n')",wait_time);
});

function switch_now_move(flg){
	now_move = flg;
	if(flg > 0){
		$("#prev_arrow,#next_arrow").css({"cursor":"wait"});
	}else{
		$("#prev_arrow,#next_arrow").css({"cursor":"pointer"});
	}
}

function stage_size(){
	//1400*460
	var window_w = $(window).width();
	if(window_w > 1400){
		set_img_h = s_img_h*window_w/s_img_w;
		$("#top_img").css({"width":window_w+"px" , "margin-left":"-"+Math.ceil(window_w/2)+"px" , "margin-top":"-"+Math.ceil(set_img_h/2)+"px"});
	}else{
		$("#top_img").css({"width":1400,"margin-left":"-700px","margin-top":"-230px"});
	}
}

function rotation_img(side){
	clearTimeout(timer);
	if(side=="p" && now_move==0){
		switch_now_move(1);
		switch(stage_flg){
			case 1:
				$("#img_stage_2").css({"left":-870});
				$("#img_stage_1").css_animate({"opacity":0,"left":870},move_speed,"easeInOutCubic");
				$("#img_stage_2").css_animate({"opacity":1,"left":5},move_speed,"easeInOutCubic",function(){switch_now_move(0); $("#img_stage_1").css({"left":-870});});
			break;
			case 2:
				$("#img_stage_1").css({"left":-870});
				$("#img_stage_2").css_animate({"opacity":0,"left":870},move_speed,"easeInOutCubic");
				$("#img_stage_1").css_animate({"opacity":1,"left":5},move_speed,"easeInOutCubic",function(){switch_now_move(0); $("#img_stage_2").css({"left":-870});});
			break
			default:
			break;
		}
		stage_flg--;
		if(stage_flg<1)stage_flg=2;
	}else if(now_move==0){
		switch_now_move(1);
		switch(stage_flg){
			case 1:
				$("#img_stage_2").css({"left":870});
				$("#img_stage_1").css_animate({"opacity":0,"left":-870},move_speed,"easeInOutCubic");
				$("#img_stage_2").css_animate({"opacity":1,"left":5},move_speed,"easeInOutCubic",function(){switch_now_move(0); $("#img_stage_1").css({"left":870});});
			break;
			case 2:
				$("#img_stage_1").css({"left":870});
				$("#img_stage_2").css_animate({"opacity":0,"left":-870},move_speed,"easeInOutCubic");
				$("#img_stage_1").css_animate({"opacity":1,"left":5},move_speed,"easeInOutCubic",function(){switch_now_move(0); $("#img_stage_2").css({"left":870});});
			break;
			default:
			break;
		}
		stage_flg++;
		if(stage_flg>2)stage_flg=1;
	}
	timer = setTimeout("rotation_img('n')",wait_time);
	return false;
}
