
	var txtGmapPoint = null;
	$(function(){

		// AJAXのキャッシュOFF
		$.ajaxSetup({ cache: false });

		$('#mainbody :header[src], #mainbody .str2img[src]').each(function(){
			var alt = $(this).text();
			$(this).html('<img src="' + $(this).attr('src') + '" alt="' + alt + '" />');
		});

		$('a.str2img img').addClass('imgfade');

		// リンクの点線除去
		$('a').focus( function(){ if(this.blur)this.blur(); });

		$('ul.col2 li:even').css({float:'left', width:'45%', clear:'both'});

		$('ul.tab li:first').addClass('on');
		$('ul.tab li a').click(function(){
			$(this).closest('ul').find('li.on').removeClass('on');
			$(this).closest('li').addClass('on');
		});

		$('#container a[href^="http://"][href!="' + root_url + '"]').addClass('blank');

		// コメント内のリンク
		$('div.content a[href^="http"]').addClass('blank');
		$('a[href$=".pdf"]').addClass('blank');
		// 別窓
		$('a.blank').live('click', function(){ this.target = "_blank"; });

		// 画像ロールオーバー
		$('img.imgover').rollover('_on');
		// 画像ロールオーバー(点滅)
		$('img.imgfade').live('mouseover', function () {
			$(this).animate({opacity:'0.6'}, {duration: 500} );
			$(this).animate({opacity:'1.0'}, {duration: "normal"});
		});

		// グローバルメニュー
		var menu = location.href;
		menu = menu.replace(root_url + '/', '');
		menu = menu.substring(0, menu.indexOf('/'));
		if (menu != '' && menu != 'admin') {
			$('ul#menu a[href*="' + menu + '"]').css('background', 'url(' + root_url + '/img/common/bki_menu_on.gif) repeat-x bottom');
		}
		var menu_img = $('#menu img[src*="mnu_' + menu + '.jpg"]').attr('src_on');
		$('#menu img[src*="mnu_' + menu + '.jpg"]').attr('src', menu_img);
		$('#menu img[src*="mnu_' + menu + '.jpg"]').attr('src_off', menu_img);

		$('#sidebar > div.menu > ul > li:has(ol)').css('height', 'auto');

//		// GoogleMap
//		$('div.gmap').each(gmap_load);
//		$('div.gpop').each(gpop_load);

//		// GoogleMapボタン
//		$('a.gpop').click(function(){
//			txtGmapPoint = $(this).attr('insert');
//		});

		$('img.resize[rel=' + font_size + ']').attr('src', $('img.resize[rel=' + font_size + ']').attr('src_on'));
		$('img.resize[rel=' + font_size + ']').attr('src_off', $('img.resize[rel=' + font_size + ']').attr('src_on'));
		$('img.resize').click(function() {
			$('img.resize[rel=' + font_size + ']').attr('src', $('img.resize[rel=' + font_size + ']').attr('src').replace('_on', ''));
			$('img.resize[rel=' + font_size + ']').attr('src_off', $('img.resize[rel=' + font_size + ']').attr('src').replace('_on', ''));
			font_size = $(this).attr('rel');
			$('img.resize[rel=' + font_size + ']').attr('src', $('img.resize[rel=' + font_size + ']').attr('src_on'));
			$('img.resize[rel=' + font_size + ']').attr('src_off', $('img.resize[rel=' + font_size + ']').attr('src_on'));
			$('#mainbody').attr('class', font_size);
			jQuery.get(root_url + '/ajax/font_size/' + font_size);
		});

		// ポップアップ
		$('a.lightpop, a:has(.lightpop)').lightpop({overlayBgColor:'#000', overlayOpacity:0.7}, {}, '', '/img/lightpop/');
		$('a.htmlpop').lightpop({overlayBgColor:'#000', overlayOpacity:0.7}, {grouping:false}, '', '/img/lightpop/');

//		// GoogleMap
//		$('input:button.link').click(function(){
//			if ($(this).attr('confirm') != undefined) {
//				if (!confirm($(this).attr('confirm'))) {
//					return;
//				}
//			}
//			location.href = $(this).attr('link');
//		});

		// メールアドレス inc/system.php->get_asciiとセットで使用
		$('a.mail_link').each(function(){
			var ascii = $(this).attr('href');
			var code = ascii.split(',');
			var mail = "";
			for (var cnt=0; cnt<code.length; cnt++) {
				mail += String.fromCharCode(code[cnt]);
			}
			$(this).attr('href', 'mailto:' + mail);
			$(this).text(mail);
		});

	});

	$(window).unload(function(){
		try {
			if (GMap2 != undefined) {
				GUnload();
			}
		} catch (e) {
			
		}
	});

	// GoogleMap
	function gmap_load () {
		var center = $(this).attr('center');
		var point  = $(this).attr('point');
		var zoom   = $(this).attr('zoom');
		var gmap   = $(this).attr('gmap');

		if (center == undefined) center = point;
		if (zoom == undefined) zoom = 13;

		if (center.indexOf(',') == -1) { $(this).hide(); return; }
		if (GMap2 == undefined) { $(this).hide(); return; }
		if (GBrowserIsCompatible() == false) { $(this).hide(); return; }

		var lat = center.substring(0,center.indexOf(','));
		var lng = center.substring(center.indexOf(',') + 1);

		GUnload();
		var map = new GMap2(document.getElementById($(this).attr('id')));
//		map.setMapType(G_HYBRID_MAP);
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		map.addControl(new GScaleControl());
		map.addControl(new GOverviewMapControl());
//		if (map.scrollWheelZoomEnabled()){
//			map.disableScrollWheelZoom();
//		}else{
//			map.enableScrollWheelZoom();
//		}

		map.setCenter(new GLatLng(lat, lng), zoom);
		map.setZoom(zoom);
		$(map).attr('zoom', zoom);

		if (point != undefined) {
			var icon = get_gicon(0);
			map.addOverlay(new GMarker(new GLatLng(lat, lng), { icon:icon }));

		} else if (gmap != undefined) {
			jQuery.getJSON(root_url + gmap, null, function(spots) {
				var manager = new GMarkerManager(map);
				var gMarker = [];
				for (var i = 0; i < spots.length; i++) {
					gMarker.push(gmap_marker(spots[i].lat, spots[i].lng, spots[i].label, root_url + spots[i].link, spots[i].cat));
				}
				manager.addMarkers(gMarker, 0);
				manager.refresh();
				map.setZoom(parseInt(map.zoom));
			});
		}
	}

//	var gicons = {};
	function gmap_marker(lat, lng, label, link, cat) {
		var point = new GLatLng(parseFloat(lat), parseFloat(lng));
		var icon = get_gicon(cat);
		var spot = new GMarker(point, { title:label, icon:icon });
		GEvent.addListener(spot, "click", function() { location.href = link; });
		return spot;
	}

	function get_gicon(cat) {
//		if (gicons[cat]) {
//			icon = gicons[cat];
//		} else {
		var icon = new GIcon();
		switch (cat) {
			case "11":
				icon.image = 'http://labs.google.com/ridefinder/images/mm_20_green.png';
				icon.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';
				icon.iconSize = new GSize(12,20);
				icon.shadowSize = new GSize(22,20);
				icon.iconAnchor = new GPoint(6,20);
				break;
			case "12":
				icon.image = 'http://labs.google.com/ridefinder/images/mm_20_blue.png';
				icon.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';
				icon.iconSize = new GSize(12,20);
				icon.shadowSize = new GSize(22,20);
				icon.iconAnchor = new GPoint(6,20);
				break;
			default:
				icon.image = '/img/icon/flag_default.png';
				icon.iconSize = new GSize(18,24);
				icon.iconAnchor = new GPoint(9,24);
				break;
		}
//		}
		return icon;
	}

	// GoogleMap
	function gpop_load () {

		$(this).googleMaps({
			latitude: 35.658632,longitude:139.745411, depth:2, 
			markers: { latitude: 35.658632, longitude: 139.745411, draggable: true }
		});

		$('#setLatLng').click(function(){
			var gmap = '#'+$(this).attr('target');
			alert($.googleMaps.mapMarkers);
		});

		
		//$(this).googleMaps({ latitude: 35.658632, longitude: 139.745411, depth: 2, markers: { latitude: 35.658632, longitude: 139.745411 } });

//		if (GBrowserIsCompatible() == false) { $(this).hide(); return; }
//
//		GUnload();
//		var latLng = new google.maps.LatLng(35.658632, 139.745411);
//		var zoom = 2;
//		var map = new google.maps.Map(this, { zoom: zoom, center: latLng, mapTypeId: google.maps.MapTypeId.ROADMAP });
//		var marker = new google.maps.Marker({ map:map, position:latLng, draggable: true });
//
//		var geocoder = new google.maps.Geocoder();
//		google.maps.event.addListener(marker, 'dragstart', function() {
//			// updateMarkerAddress('Dragging...');
//		});
//
//		google.maps.event.addListener(marker, 'drag', function() {
//			// updateMarkerStatus('Dragging...');
//			updateMarkerPosition(marker.getPosition());
//		});
//
//		google.maps.event.addListener(marker, 'dragend', function() {
//			updateMarkerStatus('Drag ended');
//			getAddress(marker.getPosition());
//		});

//		var map = new GMap2(document.getElementById($(this).attr('id')));
//		map.setMapType(G_HYBRID_MAP);
//		map.addControl(new GLargeMapControl());
//		map.addControl(new GMapTypeControl());
//		map.addControl(new GScaleControl());
//		map.addControl(new GOverviewMapControl());
//		if (map.scrollWheelZoomEnabled()){
//			map.disableScrollWheelZoom();
//		}else{
//			map.enableScrollWheelZoom();
//		}

		//map.addOverlay(new GMarker());

//		$(map).attr('zoom', zoom);
//
//		if (point != undefined) {
//			var icon = get_gicon(0);
//			map.addOverlay(new GMarker(new GLatLng(lat, lng), { icon:icon }));
//
//		} else if (gmap != undefined) {
//			jQuery.getJSON(root_url + gmap, null, function(spots) {
//				var manager = new GMarkerManager(map);
//				var gMarker = [];
//				for (var i = 0; i < spots.length; i++) {
//					gMarker.push(gmap_marker(spots[i].lat, spots[i].lng, spots[i].label, root_url + spots[i].link, spots[i].cat));
//				}
//				manager.addMarkers(gMarker, 0);
//				manager.refresh();
//				map.setZoom(parseInt(map.zoom));
//			});
//		}
	}

	function to_object (json_str) {
		return eval('(' + json_str + ')');
	}

