// JavaScript Document
// クッキーマネージャのインスタンス
var cookieManager = new CookieManager();
cookieManager.cookieShelfLife = 30;

// ページ読み込み時のイベント
Event.observe(window, 'load', function() {
   // ページ内のスムーズ移動
  $$('a[href^=#]:not([href=#])').each(function(element) {
    element.observe('click', function(event) {
      new Effect.ScrollTo(this.hash.substr(1), {duration: 0.7});
      Event.stop(event);
    }.bindAsEventListener(element))
  });
  
  // フォントサイズの読み込み
  var fontSize = cookieManager.getCookie('fontSize');
  if (fontSize) {
	  document.body.style.fontSize = fontSize;
  } else {
	  fontSize = '1.0em';
	  cookieManager.setCookie('fontSize', fontSize);
  }
  // IE7未満
  if (navigator.userAgent.match(/MSIE (5|6)/i)) {
	if (fontSize == '1.0em') Element.setStyle('standardFontSize', {'background-image' : 'url(imageIe6/bckgrnd_changeFontOn.gif)'});
	if (fontSize == '1.3em') Element.setStyle('largeFontSize', {'background-image' : 'url(imageIe6/bckgrnd_changeFontOn.gif)'});
  } else {
	if (fontSize == '1.0em') Element.setStyle('standardFontSize', {'background-image' : 'url(image/bckgrnd_changeFontOn.png)'});
	if (fontSize == '1.3em') Element.setStyle('largeFontSize', {'background-image' : 'url(image/bckgrnd_changeFontOn.png)'});
  }
  
  // アクセスランキングの設定
  var accessRanking = new Spry.Widget.CollapsiblePanel("accessRanking", {contentIsOpen:true}, 'url(image/bckgrnd_scrollMenuOpn.gif)', 'url(image/bckgrnd_scrollMenuCls.gif)', 600);
})

// フォントサイズの変更
function onChangeLargeSize() {
	var fontSize = cookieManager.getCookie('fontSize');
	if (fontSize == '1.0em') {
		document.body.style.fontSize = '1.3em';
		cookieManager.setCookie('fontSize', '1.3em');
		
		// IE7未満
		if (navigator.userAgent.match(/MSIE (5|6)/i)) {
			Element.setStyle('standardFontSize', {'background-image' : 'url(imageIe6/bckgrnd_changeFont.gif)'});
			Element.setStyle('largeFontSize', {'background-image' : 'url(imageIe6/bckgrnd_changeFontOn.gif)'});
		} else {
			Element.setStyle('standardFontSize', {'background-image' : 'url(image/bckgrnd_changeFont.png)'});
			Element.setStyle('largeFontSize', {'background-image' : 'url(image/bckgrnd_changeFontOn.png)'});
		}
	}
}
function onChangeStandardSize() {
	var fontSize = cookieManager.getCookie('fontSize');
	if (fontSize == '1.3em') {
		document.body.style.fontSize = '1.0em';
		cookieManager.setCookie('fontSize', '1.0em');

		// IE7未満
		if (navigator.userAgent.match(/MSIE (5|6)/i)) {
			Element.setStyle('standardFontSize', {'background-image' : 'url(imageIe6/bckgrnd_changeFontOn.gif)'});
			Element.setStyle('largeFontSize', {'background-image' : 'url(imageIe6/bckgrnd_changeFont.gif)'});
		} else {
			Element.setStyle('standardFontSize', {'background-image' : 'url(image/bckgrnd_changeFontOn.png)'});
			Element.setStyle('largeFontSize', {'background-image' : 'url(image/bckgrnd_changeFont.png)'});
		}
	}
}

// サイト内検索画像のロールオーバー
function onSearchQuery(obj) {
	if (document.getElementById) {
		// IE7未満
		if (navigator.userAgent.match(/MSIE (5|6)/i)) {
			obj.style.backgroundImage = 'url(imageIe6/bckgrnd_searchQueryFocus.jpg)';
		} else {
			obj.style.backgroundImage = 'url(image/bckgrnd_searchQueryFocus.png)';
		}
	}
}
function offSearchQuery(obj) {
	if (document.getElementById) {
		// IE7未満
		if (navigator.userAgent.match(/MSIE (5|6)/i)) {
			obj.style.backgroundImage = 'url(imageIe6/bckgrnd_searchQuery.jpg)';
		} else {
			obj.style.backgroundImage = 'url(image/bckgrnd_searchQuery.png)';
		}
	}
}

// リストのサブメニューのロールオーバー
function onListMenu(obj, listMenu) {
	if (listMenu != null) {
		if (listMenu.contentIsOpen) {
			obj.style.backgroundImage = 'url(image/bckgrnd_scrollMenuOpn2Hvr.gif)';
		} else {
			obj.style.backgroundImage = 'url(image/bckgrnd_scrollMenuCls2Hvr.gif)';
		}
	}
}
function offListMenu(obj, listMenu) {
	if (listMenu != null) {
		if (listMenu.contentIsOpen) {
			obj.style.backgroundImage = 'url(image/bckgrnd_scrollMenuOpn2.gif)';
		} else {
			obj.style.backgroundImage = 'url(image/bckgrnd_scrollMenuCls2.gif)';
		}
	}
}

// メールフォームのロールオーバー
function onMailForm(obj) {
	if (document.getElementById) {
		obj.style.backgroundColor = '#fffefd';
	}
}
function offMailForm(obj) {
	if (document.getElementById) {
		obj.style.backgroundColor = '#fffbf5';
	}
}

// 一般的な画像のロールオーバー
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


// Google Maps
function googlemaps() {
	if ( GBrowserIsCompatible() ) {
		
		var baseIcon = new GIcon();
		baseIcon.image = "http://allsweets.info/image/mm_20_white.png";
		baseIcon.shadow = "http://allsweets.info/image/mm_20_shadow.png";
		baseIcon.iconSize = new GSize(12, 20);
		baseIcon.shadowSize = new GSize(22, 20);
		baseIcon.iconAnchor = new GPoint(6, 20);
		baseIcon.infoWindowAnchor = new GPoint(5, 1);
		
		function GetFileName(file_url){
			file_url = file_url.substring(file_url.lastIndexOf("/")+1,file_url.length)
			file_url = file_url.substring(0,file_url.indexOf("."));
			return file_url;
		}
		
		var map = new GMap(document.getElementById("gmap"));
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		if (GetFileName(location.href) == "gmaphokkaido")			map.centerAndZoom(new GPoint(142.251256, 43.099369), 9);
		if (GetFileName(location.href) == "gmapibaraki")			map.centerAndZoom(new GPoint(140.345364, 36.319275), 8);
		if (GetFileName(location.href) == "gmaptokyo")				map.centerAndZoom(new GPoint(139.634093, 35.680067), 7);
		if (GetFileName(location.href) == "gmapkanagawa")			map.centerAndZoom(new GPoint(139.353333, 35.336414), 7);
		if (GetFileName(location.href) == "gmapniigata")			map.centerAndZoom(new GPoint(139.143220, 37.901024), 5);
		if (GetFileName(location.href) == "gmapnagano")				map.centerAndZoom(new GPoint(138.384592, 36.375174), 5);
		if (GetFileName(location.href) == "gmapshizuoka")			map.centerAndZoom(new GPoint(138.730281, 34.957995), 8);
		if (GetFileName(location.href) == "gmapaichi")				map.centerAndZoom(new GPoint(136.915505, 35.161407), 5);
		if (GetFileName(location.href) == "gmapmie")				map.centerAndZoom(new GPoint(136.726437, 34.459679), 5);
		if (GetFileName(location.href) == "gmapshiga")				map.centerAndZoom(new GPoint(136.060948, 35.168066), 7);
		if (GetFileName(location.href) == "gmapkyoto")				map.centerAndZoom(new GPoint(135.609226, 35.063866), 7);
		if (GetFileName(location.href) == "gmaposaka")				map.centerAndZoom(new GPoint(135.495640, 34.722325), 5);
		if (GetFileName(location.href) == "gmaphyogo")				map.centerAndZoom(new GPoint(135.104253, 34.784743), 7);
		if (GetFileName(location.href) == "gmapnara")				map.centerAndZoom(new GPoint(135.816271, 34.646042), 5);
		if (GetFileName(location.href) == "gmapshimane")			map.centerAndZoom(new GPoint(133.058510, 35.469898), 3);
		if (GetFileName(location.href) == "gmaptokushima")			map.centerAndZoom(new GPoint(133.770270, 33.873322), 7);
		if (GetFileName(location.href) == "gmapkochi")				map.centerAndZoom(new GPoint(133.933640, 33.535099), 6);
		if (GetFileName(location.href) == "gmapfukuoka")			map.centerAndZoom(new GPoint(130.414726, 33.554883), 5);
		if (GetFileName(location.href) == "gmapkumamoto")			map.centerAndZoom(new GPoint(130.697093, 32.790071), 4);
		if (GetFileName(location.href) == "gmapitaly") 				map.centerAndZoom(new GPoint(12.482204, 43.580639), 10);
		if (GetFileName(location.href) == "gmapbelgium")			map.centerAndZoom(new GPoint(4.352528, 50.846706), 9);
		if (GetFileName(location.href) == "gmapthenetherlands")		map.centerAndZoom(new GPoint(4.897156, 52.378114), 6);
		if (GetFileName(location.href) == "gmapusa")				map.centerAndZoom(new GPoint(-117.158203, 32.714511), 6);
		if (GetFileName(location.href) == "gmapaustralia")			map.centerAndZoom(new GPoint(145.772138, -16.92508), 4);

		function createMarker(point, index, shop, image, link, type) {
			var icon = new GIcon(baseIcon);
			if (type == "洋菓子") 				icon.image = "http://allsweets.info/image/mm_20_blue.png";
			else if (type == "和菓子")			icon.image = "http://allsweets.info/image/mm_20_red.png";
			else if (type == "パン")			icon.image = "http://allsweets.info/image/mm_20_yellow.png";
			else if (type == "洋菓子・和菓子")	icon.image = "http://allsweets.info/image/mm_20_blue_red.png";
			else if (type == "パン・洋菓子")	icon.image = "http://allsweets.info/image/mm_20_blue_yellow.png";
			var marker = new GMarker(point, icon);

			var html = "<table summary=\"店舗に関する情報です。\" style=\"background: #ffffff; border: none; height: 100%; margin: 0px; table-layout: auto; width: 250px;\"><tr><td colspan=\"2\" style=\"border-bottom: 1px dashed #d17d79; width: 250px;\"><span style=\"font-size: 16px; line-height: 1.4; letter-spacing: 0.1em;\">" + shop +"</span></td></tr><tr><td rowspan=\"2\" style=\"width: 80px;\"><img src=\"picture/" + image +"\" alt=\"店舗の写真\" title=\"店舗の写真\" heigth=\"75\" width=\"75\" style=\"margin-right: 5px; vertical-align: middle;\" /></td><td style=\"height: 38px; width: 170px;\"><span style=\"font-size: 14px; line-height: 19px; vertical-align: middle;\"> カテゴリ : " + type +"</span></td></tr><tr><td style=\"height: 37px;\"><a href = \"" + link + "\" title = \"詳細情報を見る\" style=\"font-size: 14px; line-height: 18px; vertical-align: middle;\">詳細情報を見る</a></td></tr></table>";
			GEvent.addListener(marker, "click", function() {
				marker.openInfoWindowHtml(html);
			});

			return marker;
		}

		var request = GXmlHttp.create();
		if (GetFileName(location.href) == "gmaphokkaido")			request.open("GET", "xml/gmaphokkaido.xml", true);
		if (GetFileName(location.href) == "gmapibaraki")			request.open("GET", "xml/gmapibaraki.xml", true);
		if (GetFileName(location.href) == "gmaptokyo")				request.open("GET", "xml/gmaptokyo.xml", true);
		if (GetFileName(location.href) == "gmapkanagawa")			request.open("GET", "xml/gmapkanagawa.xml", true);
		if (GetFileName(location.href) == "gmapniigata")			request.open("GET", "xml/gmapniigata.xml", true);
		if (GetFileName(location.href) == "gmapnagano")				request.open("GET", "xml/gmapnagano.xml", true);
		if (GetFileName(location.href) == "gmapshizuoka")			request.open("GET", "xml/gmapshizuoka.xml", true);
		if (GetFileName(location.href) == "gmapaichi")				request.open("GET", "xml/gmapaichi.xml", true);
		if (GetFileName(location.href) == "gmapmie")				request.open("GET", "xml/gmapmie.xml", true);
		if (GetFileName(location.href) == "gmapshiga")				request.open("GET", "xml/gmapshiga.xml", true);
		if (GetFileName(location.href) == "gmapkyoto")				request.open("GET", "xml/gmapkyoto.xml", true);
		if (GetFileName(location.href) == "gmaposaka")				request.open("GET", "xml/gmaposaka.xml", true);
		if (GetFileName(location.href) == "gmaphyogo")				request.open("GET", "xml/gmaphyogo.xml", true);
		if (GetFileName(location.href) == "gmapnara")				request.open("GET", "xml/gmapnara.xml", true);
		if (GetFileName(location.href) == "gmapshimane")			request.open("GET", "xml/gmapshimane.xml", true);
		if (GetFileName(location.href) == "gmaptokushima")			request.open("GET", "xml/gmaptokushima.xml", true);
		if (GetFileName(location.href) == "gmapkochi")				request.open("GET", "xml/gmapkochi.xml", true);
		if (GetFileName(location.href) == "gmapfukuoka")			request.open("GET", "xml/gmapfukuoka.xml", true);
		if (GetFileName(location.href) == "gmapkumamoto")			request.open("GET", "xml/gmapkumamoto.xml", true);
		if (GetFileName(location.href) == "gmapitaly")				request.open("GET", "xml/gmapitaly.xml", true);
		if (GetFileName(location.href) == "gmapbelgium")			request.open("GET", "xml/gmapbelgium.xml", true);
		if (GetFileName(location.href) == "gmapthenetherlands")		request.open("GET", "xml/gmapthenetherlands.xml", true);
		if (GetFileName(location.href) == "gmapusa")				request.open("GET", "xml/gmapusa.xml", true);
		if (GetFileName(location.href) == "gmapaustralia")			request.open("GET", "xml/gmapaustralia.xml", true);
		request.onreadystatechange = function() {
			if (request.readyState == 4) {
				var xmlDoc = request.responseXML;
				var markers = xmlDoc.documentElement.getElementsByTagName("marker");
				for (var i = 0; i < markers.length; i++) {
					var point = new GPoint(parseFloat(markers[i].getAttribute("lng")),
																			  parseFloat(markers[i].getAttribute("lat")));
					var marker = createMarker(point, i, 
						markers[i].getAttribute("shop"), markers[i].getAttribute("image"), markers[i].getAttribute("link"), markers[i].getAttribute("type"));
					map.addOverlay(marker);
				}
			}
		}
		request.send(null);
	}
	else {
	}
}