$(document).ready(function(){
	m = new Map($('#map')[0], $('#map_nl').val(), $('#map_el').val(), $('#map_zoom').val());
	if(m.init()){
		ms = {inshoku : new MarkerSet('飲食店', 'blue-pushpin', 19),
					miru : new MarkerSet('観光スポット', 'purple-pushpin', 18),
					kaimono : new MarkerSet('買い物', 'ylw-pushpin', 22),
					gnavi : new MarkerSet('ぐるなび飲食店', 'red-pushpin', 0)
					};
		m.showMap(false, false);
		m.setCenter(false);
		$.each(ms, function(target, obj){
			m.setMarkerSet(target, obj)
			$('#map_' + target)[0].checked = false;
			$('#map_' + target).click(function(){
				if(this.checked == true){
					m.showMarkerSet(target);
				}else{
					m.hideMarkerSet(target);
				}
			});
		});
		
		setTimeout(function(){
			//標準で飲食店を表示
			$('#map_inshoku')[0].checked = true;
			m.showMarkerSet('inshoku');
		},2000);

	}		
	
	/*click hatena*/
	$('#map_category_hatena').click(function(){
		$('#map_usage').show();
	});
});
	

MarkerSet.prototype.loadMarkerSet = function(){
	$('#map_loading').show();

	var me = this;
	$.ajaxSetup({async : false});
	
	if(me.id == 0){
		$.getJSON('./app/api/gnavi/json_get_neighbors', {'el' : $('#map_el').val(), 'nl' : $('#map_nl').val(), 'range' : 4}, success);
	}else{
		$.getJSON('./app/api/spot/json_tag_entries_by_category', {category_id: me.id, tag: '国際通り'}, success);
	}
	
	function success(json){
		if(json.length != 0){
			$.jGrowl(me.label + 'を' + json.length + "件表示しました", {position: 'top-left'});
			for(i=0;i<json.length;i++){
				me.addMarker(json[i]['nl'], json[i]['el'], json[i]['text']);
			}
		}else{
			$.jGrowl('登録されている情報はありませんでした', {position: 'top-left'});
		}
	};
	$('#map_loading').hide();
};
