// JavaScript Document

var map;

function addMarker( shop ) {
	var icon = new GIcon();
	if( shop.icon == 'gourmet1' ) {
		icon.image  = "http://www.poroco.co.jp/map/gourmet/img/pin1.png";
		icon.iconSize   = new GSize(40, 47);
		icon.iconAnchor = new GPoint(5, 43);
		icon.infoWindowAnchor = new GPoint(10, 30);
	} else if( shop.icon == 'gourmet2' ) {
		icon.image  = "http://www.poroco.co.jp/map/gourmet/img/pin2.png";
		icon.iconSize   = new GSize(24, 31);
		icon.iconAnchor = new GPoint(4, 25);
		icon.infoWindowAnchor = new GPoint(7, 20);
	}
	var latlng = new GLatLng( shop.lat_google, shop.lon_google );
	var marker = new GMarker( latlng, {icon:icon} );
	GEvent.addListener( marker, 'click', function() {
		marker.openExtInfoWindow(
			map,
			"custom_info_window_porocomap",
			shop.html,
			{beakOffset: 2}
		);
	});
	map.addOverlay( marker );
};

function allIn( shops ) {
	var lats = [];
	var lngs = [];
	for( i = 0; i < shops.length; i++ ) {
		lats[i] = shops[i].lat_google;
		lngs[i] = shops[i].lon_google;
	}
	var sw = new GLatLng( lats.slice(0).sort()[0], lngs.slice(0).sort()[0] );
	var ne = new GLatLng( lats.slice(0).sort().reverse()[0], lngs.slice(0).sort().reverse()[0] );
	var lv = map.getBoundsZoomLevel( new GLatLngBounds( sw, ne ) );
	var lat = sw.lat() + ( ne.lat() - sw.lat() ) / 2;
	var lng = sw.lng() + ( ne.lng() - sw.lng() ) / 2;
	var center = new GLatLng( lat, lng );
	map.setCenter( center, lv );
}

function init(){
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("map_canvas"));
		map.addControl(new GSmallMapControl());
		map.setCenter(new GLatLng( 0, 0 ), 13);
//		GEvent.addListener( map, 'load', function() {
			parent.ready();
//		});
	}
};

