$(function() {
	
	// #photo_areaを使用しているページのみ実行
	if ( $("#photo_area") ) {
		$("#photo_area").hide();
		setTimeout( function() {
			$("#photo_area").fadeIn(2000);
		}, 700 );
	}
	
	
	// .styleを使用しているページのみ実行
	if ( $("#content.style") ) {
		
		$("#style_photo ul li img").eq(1).css( {"z-index":"100" , "width":"334px", "top":"-100px" , "left":"-67px" , "opacity":"1"} );
		$("#style_photo ul li img").eq(0).css( {"z-index":"1" , "width":"200px", "top":"0" , "left":"0" , "opacity":"0.5"} );
		$("#style_photo ul li img").eq(2).css( {"z-index":"1" , "width":"200px", "top":"0" , "left":"0" , "opacity":"0.5"} );
		
		var i = 0;
		
		$("#style_photo ul li img").each( function() {
			$(this).css( {"margin-left": i * (60+200) + "px"});
			i++;
		});
		
		var count = 0; // ボタンクリック回数
		var count_max =  $("#style_photo ul li img").size() -1;
		var flg = 1; // 処理速度による画像のずれ防止フラグ
		
		function style_overphoto_func(check_count) {
			if(!flg) return false;
			flg = 0;
			
			var left_position = 0;
			
			if (check_count) {
				count++;
			}else {
				count--;
			}
			
			// 写真の枚数の上限をcountが超えるか、又はcountが0以下の場合、countを0に戻す
			if (count <= 0 || count_max < count+1) {
				count = 0;
			}else {
				// 通常の写真移動処理
				left_position = count * -260 + "px";
			}
			
			$("#style_photo ul").animate( {"left": left_position },400);
			
			var i_animate = 0;
			
			$("#style_photo ul li img").eq(count+1).addClass("main").css({"z-index":"100"}).animate( {"width":"334px","top":"-100px","left":"-67px","opacity":"1"},400);
			$("#style_photo ul li img").not(".main").css({"z-index":"1"}).animate( {"width":"200px","top":"0","left":"0","opacity":"0.5"}, function() {
				i_animate++;
				
				if(i_animate == count_max - 1) {
					$("#style_photo ul li img").removeClass("main");
					flg = 1;
				}
			});
		}
		
		$("#right_btn a").click(function() {
			style_overphoto_func(1);
			return false;
		});
		$("#left_btn a").click(function() {
			if (count) style_overphoto_func(0);
			return false;
		});
	
	}

});

