// JavaScript Document

$(function(){
	
	$('#contents a img').not('img[src*="_off."]').hover(
		function () {
			$(this).css('opacity', 0.8);
		},
		function () {
			$(this).css('opacity', 1);
		}
	);
	
	//var domain = location.href.match(/^https?(:\/\/[a-zA-Z0-9.]+)\//i)[1];
	$("a[href^=http]").not('[href*="www.fp-group.gr.jp"]').attr("target","_blank");
	
	$("a[href^=#]").click(function(){
		var elmID = $(this).attr("href");
		var posi = 0;
		
		if($(elmID).size()){
			posi = $(elmID).offset().top;
			$("html,body").animate({
				scrollTop: posi
			}, 1000);
			return false;
		}
	});
	
	$(".fp_map").click(function(e) {
			$("#smileFlash").hide();
		if($("#area_list").size() == 0 || $("#area_list").css("display") == "none"){
			$("#fp_map").animate({height: "show"}, 500, "swing",function(){
				$("#footer .map_close").show(500);
			});
		}else{
			$("#footer .branch_close").animate({height: "hide"}, 300, "swing",function(){
				$("#area_list").animate({height: "hide"}, 500, "swing",function(){
					$("#fp_map").animate({height: "show"}, 500, "swing",function(){
						//$("#footer .map_close").animate({height: "show"}, 300, "swing");
						$("#footer .map_close").show(500);
					});
				});
			});
		}
		return false;
    });
	$(".fp_branch").click(function(e) {
		if($("#fp_map").css("display") == "none"){
			$("#area_list").animate({height: "show"}, 500, "swing",function(){
				FpBranchOpen();
			});
		}else{
			$("#footer .map_close").animate({height: "hide"}, 300, "swing",function(){
				$("#fp_map").animate({height: "hide"}, 500, "swing",function(){
					$("#area_list").animate({height: "show"}, 500, "swing",function(){
						FpBranchOpen();
					});
				});
			});
		}
		return false;
    });
	
	//閉じる
	$("#footer .map_close a,#footer .branch_close a").click(function(e) {
		FootClose();
		return false;
    });
	
	//フッター会員リスト
	if($("#footer #branch_frame .branch_box").size()){
		FootBranchInit();
	}
	
	
	//レイアウト調整
	$("#detailContentsArea .fi_img2 li:last").css("margin-right","0");
	
});

var openFlg;
function FpBranchOpen(){
	$("#footer .branch_close").show(500);
	if(!openFlg){
		$("#area_tab img:first").FootTabClick();
		openFlg = true;
	}
}

function FootClose(){
	$("#footer .map_close").animate({height: "hide"}, 300, "swing",function(){
		$("#fp_map").animate({height: "hide"}, 500, "swing",function(){
			$("#smileFlash").show();
		});
	});
	$("#footer .branch_close").animate({height: "hide"}, 300, "swing",function(){
		$("#area_list").animate({height: "hide"}, 500, "swing");
	});
}

//フッター会員リスト
var margin = 0;
function FootBranchInit(){
	var totalWidth = 0;
	$("#footer #branch_frame .branch_box").each(function(index, element) {
        $(this).width($(this).closest("div").width());
		$(this).css("float","left");
		totalWidth += 960;
    });
	$("#footer #branch_frame").width(totalWidth);
	$("#footer #branch_frame").css("overflow","hidden");
	$("#footer #branch_frame").css("height","0");
	$("#footer #area_list .count_area").not(":first").hide();
	
	$("#area_tab img").click(function(e) {
		if(!$("#footer div:animated").size()){
			$(this).FootTabClick();
		}
    });
}

jQuery.extend(jQuery.fn, {
	FootTabClick: function() {
		var tabID = $(this).attr("src").split("_");
		var tmp = tabID.pop(); 
		var tabID = tabID.pop(); 
		
		$("#area_tab img").each(function(index, element) {
			$(this).attr("src",$(this).attr("src").replace("_on","_off"));
		});
		$(this).attr("src",$(this).attr("src").replace("_off","_on"));
		
		//スライド
		margin = margin - $("#"+tabID).position().left;
		$("#footer #branch_frame").animate({
			marginLeft: margin,
			height: $("#"+tabID).height()
		}, 500 );
		
		$("#footer #area_list .count_area").hide();
		$("#footer #area_list #count"+tabID).show();
	}
});







