/*
======== table of content. =================================

summary: show GoogleMap

============================================================
*/

new function() {
	
	var map = null;
	var target = null;
	var guide = [];
	
	var areaID = 'map_canvas';
	var defaultCenter = new GLatLng( 34.69509787192177, 135.47413408756256 );
	var defaultZoom = 18;
	var mapIcon = './images/gmap_icon_hd.png';
	var mapShadow = './images/gmap_icon_hd_s.png';
	var iconTitle = '株式会社ホシカワデザイン';
	var iconPoint = new GLatLng( 34.695413669273925, 135.47395437955856 );
	
	var guideClass = 'map_guide';
	var lineColor = '#000000';
	var lineWidth = 3;
	
	
	if ( window.addEventListener ) {
		window.addEventListener( 'load', init, false );
	}
	else {
		window.attachEvent( 'onload', init );
	}
	
	/**
	 * 初期化
	 */
	function init() {
		
		if ( GBrowserIsCompatible() ) {
			
			// マップ生成
			map = new GMap2( document.getElementById( areaID ) );
			map.setCenter( defaultCenter, defaultZoom );
			map.addControl( new GSmallMapControl() );
			// map.setUIToDefault();
			
			// アイコン生成
			var icon = new GIcon();
			icon.image = mapIcon;
			icon.shadow = mapShadow;
			icon.iconSize = new GSize( 56, 49 );
			icon.shadowSize = new GSize( 77, 49 );
			icon.iconAnchor = new GPoint( 28, 48 );
			
			target = new GMarker( iconPoint, {
				'icon': icon,
				'title': iconTitle
			});
			
			map.addOverlay( target );
			
			// クリックイベント
			$( '.' + guideClass ).
				click( onClickGuide );
			
		}
	}
	
	/**
	 * ガイド表示
	 */
	function onClickGuide( e ) {
		
		// リセット
		var i = guide.length;
		
		while ( guide[ --i ] ) {
			guide[ i ].remove();
		}
		
		guide = [];
		
		// ガイド振り分け
		var key = $(this).attr( 'href' ).substr( 1 );
		
		switch ( key ) {
			case 'view-guide-1':
				showGuide1();
				break;
			case 'view-guide-2':
				showGuide2();
				break;
			case 'view-guide-3':
				showGuide3();
				break;
			default:
				break;
		}
		
		return false;
	}
	
	/**
	 * ガイド表示１
	 * 阪神電鉄本線 野田駅より
	 */
	function showGuide1() {
		
		// 画面
		var center = new GLatLng( 34.69488175294601 , 135.47524452209473 );
		var zoom = 18;
		
		map.setCenter( center, zoom );
		
		// ガイド
		var title = '阪神電鉄本線 野田駅';
		var points = [
			new GLatLng( 34.694586683500894, 135.47589629888535 ),
			new GLatLng( 34.694672690406314, 135.4749172925949 ),
			new GLatLng( 34.69464843205743, 135.4747912287712 ),
			new GLatLng( 34.694818240350315, 135.47473222017288 ),
			new GLatLng( 34.694785160840055, 135.4746437072754 ),
			new GLatLng( 34.69487337283804, 135.47460079193115 ),
			new GLatLng( 34.695380590001676, 135.47418773174286 ),
			new GLatLng( 34.69537617943103, 135.4739785194397 )
		];
		
		var marker = new GMarker( points[0], {
			'title': title,
			'icon': new GIcon(G_DEFAULT_ICON)
		});
		
		map.addOverlay( marker );
		guide.push( marker );
		
		var line = new GPolyline( points, lineColor, lineWidth );
		
		map.addOverlay( line );
		guide.push( line );
	}
	
	/**
	 * ガイド表示２
	 * 地下鉄千日前線 野田阪神駅 2番出口より
	 */
	function showGuide2() {
		
		// 画面
		var center = new GLatLng( 34.69487116753923, 135.47431111335754 );
		var zoom = 18;
		
		map.setCenter( center, zoom );
		
		// ガイド
		var title = '地下鉄千日前線 野田阪神駅 2番出口';
		var points = [
			new GLatLng( 34.694758697222355, 135.474573969841 ),
			new GLatLng( 34.69475428661856, 135.4746276140213 ),
			new GLatLng( 34.694785160840055, 135.4746437072754 ),
			new GLatLng( 34.69487337283804, 135.47460079193115 ),
			new GLatLng( 34.695380590001676, 135.47418773174286 ),
			new GLatLng( 34.69537617943103, 135.4739785194397 )
		];
		
		var marker = new GMarker( points[0], {
			'title': title,
			'icon': new GIcon(G_DEFAULT_ICON)
		});
		
		map.addOverlay( marker );
		guide.push( marker );
		
		var line = new GPolyline( points, lineColor, lineWidth );
		
		map.addOverlay( line );
		guide.push( line );
	}
	
	/**
	 * ガイド表示３
	 * JR東西線 海老名駅 1番出口より
	 */
	function showGuide3() {
		
		// 画面
		var center = new GLatLng( 34.695155650599666, 135.4738900065422 );
		var zoom = 19;
		
		map.setCenter( center, zoom );
		
		// ガイド
		var title = 'JR東西線 海老名駅 1番出口';
		var points = [
			new GLatLng( 34.69487778343545, 135.47412604093552 ),
			new GLatLng( 34.69528135210557, 135.4736566543579 ),
			new GLatLng( 34.69537617943103, 135.4739785194397 )
		];
		
		var marker = new GMarker( points[0], {
			'title': title,
			'icon': new GIcon(G_DEFAULT_ICON)
		});
		
		map.addOverlay( marker );
		guide.push( marker );
		
		var line = new GPolyline( points, lineColor, lineWidth );
		
		map.addOverlay( line );
		guide.push( line );
	}
}
