function swapimg(obj) {
	if(obj.src.match(/_f2.(jpg|gif|png)/)) {
		obj.src = obj.src.replace('_f2', '');
	} else {
		obj.src = obj.src.replace(/\.(jpg|gif|png)$/, "_f2.$1");
	}
}


/* Google Map
==========================================*/
window.onload = function() {
	var DIVs = document.getElementsByTagName('div');
	var MapCount = 0;
	for (var Count = 0; Count < DIVs.length; Count ++) {
		if (DIVs[Count].id.match(/^aagmap\d*$/)) {
			var Info = document.getElementById(DIVs[Count].id).innerHTML.split("|");
			Info[0] = Info[0].replace(/^\s*/, "");
			CreateMap(DIVs[Count].id, Info);
		}
	}
}

function CreateMap(GmapID, Info) {
	/*
	Info
		0:住所（必須）
		1:緯度・経度指定
		2:情報ウィンドウ内テキスト
		3:縮尺レベル
		4:道のりスタート住所指定 or 緯度・経度指定
	*/

	if (Info[1]) {
		// 座標指定
		var Lat = Info[1].replace(/(\d+\.\d+),\d+\.\d+/, "$1");
		var Lng = Info[1].replace(/\d+\.\d+,(\d+\.\d+)/, "$1");
		ViewMap(GmapID, new google.maps.LatLng(Lat, Lng), Info);
	} else {
		// ジオコーディング
		var Geocoder = new google.maps.Geocoder();
		Geocoder.geocode(
			{
				address: Info[0]
			},
			function(Results, Status) {
				if (Status == google.maps.GeocoderStatus.OK) {
					ViewMap(GmapID, Results[0].geometry.location, Info);
				} else {
					document.getElementById(GmapID).innerHTML = '現在、システムが混みあっています。';
					document.getElementById(GmapID).style.visibility = "visible";
				}
			}
		);
	}
}

// 地図表示処理
function ViewMap(GmapID, TargetLatLng, Info) {
	var ViewInfo = Info[2] || Info[0];
	var ZoomLevel = parseInt(Info[3]);
	ZoomLevel = isNaN(ZoomLevel) ? 12 : ZoomLevel;

	// 地図作成
	var Map = new google.maps.Map(
		document.getElementById(GmapID),
		{
			zoom: ZoomLevel,
			center: TargetLatLng,
			mapTypeId: google.maps.MapTypeId.ROADMAP
		}
	);

	// マーカー作成
	var Marker = new google.maps.Marker(
		{
			map: Map,
			position: TargetLatLng
		}
	);

	// 情報ウィンドウ作成
	var InfoWindow = new google.maps.InfoWindow(
		{
			content: ViewInfo
		}
	);

	// マーカークリック
	google.maps.event.addListener(Marker, 'click', function() {
		InfoWindow.open(Map, Marker);
	})

	// 経路処理
	if (Info[4]) {
		var StartLatLng;
		if (Info[4].match(/\d+\.\d+,\d+\.\d+/)) {
			// 座標指定
			var Lat = Info[4].replace(/(\d+\.\d+),\d+\.\d+/, "$1");
			var Lng = Info[4].replace(/\d+\.\d+,(\d+\.\d+)/, "$1");
			ViewRoute(Map, new google.maps.LatLng(Lat, Lng), TargetLatLng);
		} else {
			// ジオコーディング
			var Geocoder = new google.maps.Geocoder();
			Geocoder.geocode(
				{
					address: Info[4]
				},
				function(Results, Status) {
					if (Status == google.maps.GeocoderStatus.OK) {
						ViewRoute(Map, Results[0].geometry.location, TargetLatLng);
					} else {
						document.getElementById(GmapID).innerHTML = '現在、システムが混みあっています。';
						document.getElementById(GmapID).style.visibility = "visible";
					}
				}
			);
		}
	}

	// 地図表示
	document.getElementById(GmapID).style.visibility = "visible";

	// 情報ウィンドウ表示
	//InfoWindow.open(Map, Marker);
}

// 経路表示処理
function ViewRoute(Map, StartLatLng, TargetLatLng) {
	// 経路計算
	var DirectionsService = new google.maps.DirectionsService();
	DirectionsService.route(
		{
			origin: StartLatLng,
			destination: TargetLatLng,
			travelMode: google.maps.DirectionsTravelMode.WALKING
		},
		function(Result, Status) {
			if (Status == google.maps.DirectionsStatus.OK) {
				DirectionsDisplay.setDirections(Result);
			}
		}
	);

	// 経路表示
	var DirectionsDisplay = new google.maps.DirectionsRenderer();
	DirectionsDisplay.setMap(Map);
}



$(document).ready(function() {

//代理店

	$(".JDMapDetail1").each(function(){
		$(this).css("display","none");
		
	});
	
	$("#JDMap1_1").css("display","block");
	
	//$("#shop .LMCD_B1 .CD2").css("display","none");


	$("#JDShopMap1 .CI1").mouseover(function(){
		
		$("#JDShopMap1 .CI1").each(function(){
			var srcPath = $(this).attr("src").replace("_f2","");
			$(this).attr("src",srcPath);
			$(this).parents("p").css("z-index",100);
		});
		$(this).parents("p").css("z-index",200);
		$("#JDShopMap1 .CI2").each(function(){
			$(this).css("display","none");
		});
		$(this).parents("p").find(".CI2").css("display","inline");
		var srcPath1 = $(this).attr("src").replace(".jpg","_f2.jpg");
		$(this).attr("src",srcPath1);
	});
	
	$("#JDShopMap1 .CI1").mouseout(function(){
		$("#JDShopMap1 .CI1").each(function(){
			var srcPath = $(this).attr("src").replace("_f2","");
			$(this).attr("src",srcPath);
		});
		$("#JDShopMap1 .CI2").each(function(){
			$(this).css("display","none");
		});
	});
	
	$("#JDShopMap1 .CI1").click(function(){
		$("#shop .LMCD_B1 .CD2").css("display","block");
		$(".JDMapDetail1").each(function(){
			$(this).css("display","none");
		});
		var objName = $(this).parents("p").attr("id").replace("JPShopMap","#JDMap");
		$(objName).css("display","block");
	});


	
});





