/*
	Map'n Go Asuka Edition
*/
var drawMapFlag = false;

jQuery(function(){
	$button = jQuery('.map_button');
	jQuery('.map_button').click(function(){
		if( jQuery('body.map_enable').size() > 0 ){
			// hide map
			hideMap();
		} else {
			// show map
			showMap();
		}
	});
	if(getUrlVars().indexOf("map") >= 0 ){
		showMap();
	}
});

function showMap(){
	jQuery('body').children().hide();
	jQuery('#map').show();
	jQuery('#map_menu').show();
	jQuery('body').addClass('map_enable');
	if(drawMapFlag == false){
		drawMap();
		drawMapFlag = true;
	}
}
function hideMap(){
	jQuery('body').children().show();
	jQuery('#map').hide();
	jQuery('#map_menu').hide();
	jQuery('body').removeClass('map_enable');
}

function drawMap(){
	var map = new google.maps.Map(
		document.getElementById('map') ,
		{
			zoom: 12,
			center: new google.maps.LatLng(center.y, center.x),
			mapTypeId: google.maps.MapTypeId.ROADMAP,
			mapTypeControl: false,
			scaleControl: true,
		}
	);
	// こびと表示
	plotMarker(map, new google.maps.LatLng(center.y, center.x), base_url+"/img/dwarf.png", dwarf_html);
	
	for (var i = 0; i < data.length; i ++) {
		plotMarker(map, new google.maps.LatLng(data[i][0]['y'] ,data[i][0]['x']), base_url+"/img/map_icon.gif", data[i][1]);
	}
}
function plotMarker(map, myLatLng, image, html){
	var marker = new google.maps.Marker({
			position: myLatLng,
			map: map,
			icon: image
	});
	var infowindow = new google.maps.InfoWindow({
		content: '<div style="width:300px;">'+html+'</div>'
	});
	google.maps.event.addListener(marker, 'click', function() {
		infowindow.open(map, marker);
	});
}
function getUrlVars(){
	var vars = [], hash; 
	var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); 
	for(var i = 0; i < hashes.length; i++) { 
		hash = hashes[i].split('='); 
		vars.push(hash[0]); 
		vars[hash[0]] = hash[1]; 
	} 
	return vars; 
}
