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");
	}
}

$(document).ready(function() {

//シンプルモーダル
$("#LM .JAModal1").click(function (e) {
	e.preventDefault();
	
	var src = $(this).attr("href").replace("#JAModal","") + ".html";

	$.modal('<div class="SDModalWrap1"><iframe src="' + src + '" height="506" width="736" style="border:0; overflow:hidden;" scrolling="no"></iframe><p class="CPClose"><a href="#"><img src="./img/base/BtnClose1.jpg" /></a></p></div>', {
			onShow: function (dialog) {
				$(".CPClose").click(function () {
					e.preventDefault();
					dialog.container.fadeOut('slow', function () {
						dialog.overlay.fadeOut('slow');
						$.modal.close();
					});
				});
			},
			overlayClose:true
		});
		
		

		return false;

});


//4つの約束モーダル
$("#LM #JSpnPromiseLink1").click(function (e) {
	e.preventDefault();
	
	var obj = $("#JDPromiseLink1");
	$(obj).modal({
		onOpen: function (dialog) {
			dialog.overlay.fadeIn('fast', function () {
				dialog.data.hide();
				dialog.container.fadeIn('fast', function () {
					dialog.data.fadeIn('fast');
				});
			});
			
			
			
		},
		onShow: function (dialog) {
		},
		onClose: function (dialog) {
			dialog.container.fadeOut('fast', function () {
				dialog.overlay.fadeOut('fast', function () {
					$.modal.close(); // must call this!
				});
			});
		},
		overlayClose:true,
		opacity: 0,
		closeClass:"JIClose1"
	});
	return false;

});

//フレッシュゆめ工場モーダル
//4つの約束

$("#JSpnDream1").css("position","relative").css("z-index","300");
$("#JSpnDream2").css("display","none");
$("#JIDream1").css("position","absolute").css("top","-324px").css("left","-100px");
$("#JIDream2").css("position","absolute").css("top","-65px").css("left","486px");

$("#JSpnDreamLink1").click(function(){
	$("#JSpnDream2").css("display","inline");
});


$("#JIDream2").click(function(){
	$("#JSpnDream2").css("display","none");
});




//トグル
$("#JDToggle1 .CD1").each(function(){
	$(this).css("display","none");
});

$("#JDToggle1 .SUToggle1 li .CH1").click(function(e){
	e.preventDefault();
	
	if( $(this).hasClass("ROn") ){
		$("#JDToggle1 .SUToggle1 li h4.CH1").each(function(){
			$(this).removeClass("ROn");
			$(this).next("div").css("display","none");
		});
	}
	else {
		$("#JDToggle1 .SUToggle1 li h4.CH1").each(function(){
			$(this).removeClass("ROn");
			$(this).next("div").css("display","none");
		});
		$(this).addClass("ROn");
		$(this).next("div").css("display","block");
	}


});



});




//トップページモーダル


function funcOpenLarge1(){

	var obj = $("#JDFlashMovie1");
	$(obj).modal({
		containerId:"SDTopFlash1W1",
		containerCss:{
			width:"100%",
			height:340,
			padding:0,
			background:"none"
		},
		onOpen: function (dialog) {
			dialog.overlay.fadeIn('fast', function () {
				dialog.data.hide();
				dialog.container.fadeIn('fast', function () {
					dialog.data.fadeIn('fast');
				});
			});
			
			
			
		},
		onShow: function (dialog) {
		},
		onClose: function (dialog) {
			dialog.container.fadeOut('fast', function () {
				dialog.overlay.fadeOut('fast', function () {
					$.modal.close(); // must call this!
				});
			});
		},
		overlayClose:true,
		position:[70, 0],
		opacity: 70
	});
	return false;
	
}




function funcCloseLarge1(time){
	$.modal.close();
}


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) ? 17 : 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);
}



