/**
 * toneri/Map.js
 * 
 * Map Class
 *
 * @requires jQuery
 * @copyright ingcyte corporation.
 */
var toneri=function(){};toneri.Map=function(e,b,d,c,a){this.map=new GMap2(document.getElementById("map"),{size:new GSize(c,a)});this.map.addControl(new GLargeMapControl());this.map.addControl(new GMapTypeControl());this.map.addControl(new GScaleControl());this.map.setCenter(new GLatLng(e,b),d);this.baseIcon=new GIcon();this.baseIcon.shadow="/img/ico_shadow.png";this.baseIcon.iconSize=new GSize(24,24);this.baseIcon.shadowSize=new GSize(32,24);this.baseIcon.iconAnchor=new GPoint(12,12);this.baseIcon.infoWindowAnchor=new GPoint(10,2);this.estate=new Array();this.community=new Array();this.bank=new Array();this.hotspring=new Array();this.hospital=new Array();this.store=new Array();this.leisure=new Array();this.sightseeing=new Array();this.restaurant=new Array();this.hotel=new Array();this.catString={community:"公共",bank:"金融",hotspring:"温泉",leisure:"レジャー",store:"生活",hospital:"医療",sightseeing:"観光"}};toneri.Map.prototype={setImageSize:function(f,c){var a=f.substring(0,f.lastIndexOf("/"));var b=f.substring(f.lastIndexOf("/")+1,f.length);var e=b.substring(0,b.indexOf("."));var d=b.substring(b.indexOf(".")+1,b.length);return a+"/"+e+"-"+c+"."+d},createMarker:function(c,e){var b=this;var a=new Array();var d=new GIcon(this.baseIcon);d.image="/img/ico_"+e+".png";$.each(c,function(h,j){var f=new GMarker(new GLatLng(j.latitude,j.longitude),{icon:d,hide:true});var g='<div class="balloon"><h3><a href="/fac/'+j.id+'">'+j.title+'</a></h3><p class="thumbnail"><a href="/fac/'+j.id+'"><img src="'+b.setImageSize(j.fname,"m")+'" width="180" height="120" alt="'+j.title+'" /></a></p><p>['+b.catString[e]+"]</p></div>";GEvent.addListener(f,"click",function(){f.openInfoWindowHtml(g)});b.map.addOverlay(f);a.push(f)});return a},createHotelMarker:function(c){var b=this;var a=new Array();var d=new GIcon(this.baseIcon);d.image="/img/ico_hotel.png";$.each(c,function(f,g){var e=new GMarker(new GLatLng(g.latitude,g.longitude),{icon:d,hide:true});GEvent.addListener(e,"click",function(){var h=new Image();h.src=g.fname;h.onload=function(){var i=180*h.height/h.width;var j='<div class="balloon"><h3><a href="/hotel/'+g.id+'">'+g.title+'</a></h3><p class="thumbnail"><a href="/hotel/'+g.id+'"><img src="'+h.src+'" width="180" height="'+i+'" alt="'+g.caption+'" /></a></p><p>提供：じゃらん</p></div>';e.openInfoWindowHtml(j)}});b.map.addOverlay(e);a.push(e)});return a},createRestaurantMarker:function(c){var b=this;var a=new Array();var d=new GIcon(this.baseIcon);d.image="/img/ico_restaurant.png";$.each(c,function(f,g){var e=new GMarker(new GLatLng(g.latitude,g.longitude),{icon:d,hide:true});GEvent.addListener(e,"click",function(){var h=new Image();h.src=g.fname;h.onload=function(){var i=180*h.height/h.width;var j='<div class="balloon"><h3><a href="/rest/'+g.id+'">'+g.title+'</a></h3><p class="thumbnail"><a href="/rest/'+g.id+'"><img src="'+h.src+'" width="180" height="'+i+'" alt="'+g.caption+'" /></a></p><p>提供：ぐるなび</p></div>';e.openInfoWindowHtml(j)}});b.map.addOverlay(e);a.push(e)});return a},addEstateMarker:function(f,b,d){var e=new GIcon(this.baseIcon);e.image="/img/ico_estate.png";var c=1;var a=new GMarker(new GLatLng(f,b),{zIndexProcess:function(){return c},icon:e});GEvent.addListener(a,"click",function(){a.openInfoWindowHtml(d)});this.map.addOverlay(a);this.estate.push(a)},getItems:function(){var c=this;var b=this.map.getCenter();var e=this.map.getBounds();var a=e.getSouthWest();var f=e.getNorthEast();var d={centerLat:b.lat(),centerLng:b.lng(),swLat:a.lat(),swLng:a.lng(),neLat:f.lat(),neLng:f.lng()};$.ajax({type:"POST",dataType:"json",data:{json:$.toJSON(d)},chache:false,url:"/map/cat",timeout:12000,beforeSend:function(){$(":checkbox").attr("checked",false).attr("disabled",true)},success:function(g){$.each(g,function(j,h){if(h.length>0){switch(j){case"community":c.community=c.createMarker(h,j);$(":checkbox#community").attr("disabled",false).attr("checked",false);break;case"bank":c.bank=c.createMarker(h,j);$(":checkbox#bank").attr("disabled",false).attr("checked",false);break;case"hotspring":c.hotspring=c.createMarker(h,j);$(":checkbox#hotspring").attr("disabled",false).attr("checked",false);break;case"hospital":c.hospital=c.createMarker(h,j);$(":checkbox#hospital").attr("disabled",false).attr("checked",false);break;case"store":c.store=c.createMarker(h,j);$(":checkbox#store").attr("disabled",false).attr("checked",false);break;case"leisure":c.leisure=c.createMarker(h,j);$(":checkbox#leisure").attr("disabled",false).attr("checked",false);break;case"sightseeing":c.sightseeing=c.createMarker(h,j);$(":checkbox#sightseeing").attr("disabled",false).attr("checked",false);break;case"hotel":c.hotel=c.createHotelMarker(h);$(":checkbox#hotel").attr("disabled",false).attr("checked",false);break;case"restaurant":c.restaurant=c.createRestaurantMarker(h);$(":checkbox#restaurant").attr("disabled",false).attr("checked",false);break;default:break}}})},error:function(){},complete:function(){}})},showMarker:function(category){var markerArray=eval("this."+category);if(markerArray.length>0){for(var i in markerArray){markerArray[i].show()}}},hideMarker:function(category){var markerArray=eval("this."+category);if(markerArray.length>0){for(var i in markerArray){markerArray[i].hide()}}},moveCenter:function(b,a){this.map.closeInfoWindow();this.map.panTo(new GLatLng(b,a))}};
