var NAVERAPI = {
	description    : "네이버 오픈API 래퍼클래스",
	version        : "0.5",
	apiKey         : "245204515bca650ca48d60e16b5a7981",
	apiUri         : "/aing/naverAPIRest.php",
	infoWindow     : MAP.infoWindow(),

	getRestaurantInfo: function(keyWord) {
		keyWord = keyWord || "";

		$.getJSON(NAVERAPI.apiUri, {"query":keyWord}, function(arrRetValue) {
			if ( arrRetValue.total > 0 ) {
				var rNameList   = "<ul>";

				$.map(arrRetValue.item, function(retValue, idx) {
					var gMapX       = arrRetValue.gAddress.x;
					var gMapY       = arrRetValue.gAddress.y;

					var content     = "";
					var rName       = retValue.title;
					var homepage    = retValue.link;
					var description = retValue.description;
					var rPhone      = retValue.phone;
					var rAddr       = retValue.addr;
					var mapX        = retValue.mapX;
					var mapY        = retValue.mapY;
					var point       = MAP.setPoint(mapX, mapY);
					var marks       = MAP.setMarks(point, MAP.setIcon("/images/aing/icon_01.png", 35, 40));

					var mapDistance = MAP.setPoint(gMapX, gMapY);
					var distance    = mapDistance.distance(MAP.setPoint(mapX, mapY));
					distance        = parseInt(distance);
					distanceText    = NAVERAPI.calDistance(distance);

					rNameList      += "<li style='border-bottom:1px solid #CCC;padding-left:5px;list-style:none;'><span class='restaurantListForMap' x='"+mapX+"' y='"+mapY+"' phone='"+rPhone+"' style='padding:0 0 0 5px;font-size:9pt;float:left;'>"+rName+"</span> <span id=addRestaurant_"+idx+" class='addRestaurant' phone='"+rPhone+"' addr='"+rAddr+"' rname='"+rName+"' style='float:right;padding:0 10px 0 0;cursor:pointer;font-size:9pt;' alt='"+description+"'>식당등록</span></li>";

					MAP.mainMap.addOverlay(marks);
					MAP.mainMap.addOverlay(NAVERAPI.infoWindow);

					content  = "<div style='width:141px;height:17px;'><div style='color:#FFF; font-size:10pt;float:left; font-weight:bold;'>"+rName+"</div><div style='color:#FFF; font-size:9pt;cursor:pointer;float:right;' onclick='NAVERAPI.infoWindow.hideWindow();'>닫기</div></div>";
					content += "<div style='color:#EEE; font-size:9pt;border-bottom:1px solid #CCC;width:98%;'>"+rPhone+"</div>";
					content += "<div style='color:#FFF; font-size:9pt;padding:5px 0 0 0;'>모임으로 부터 <br/><span title='"+distance+"미터' style='text-decoration:underline;cursor:pointer;'>"+distanceText+"</span> 떨어짐</div>";

					MAP.addEvent(marks, "click", function(point) {
						NAVERAPI.infoWindow.set(point, '<div style="width:150px; height:80px;background:url(http://onionmen.iruis.net/images/aing/bg.png) no-repeat;padding:5px;">' + content + '</div>');
						NAVERAPI.infoWindow.showWindow();
					});
				});

				rNameList += "</ul>";
				$("#restaurantListText").html(rNameList);
			}
		});
	},

	calDistance: function(distance) {
		var distanceText = "";

		if ( distance < 500 ) {
			distanceText = "아주조금";
		} else if ( distance < 1000 ) {
			distanceText = "조금멀리";
		} else if ( distance < 2000 ) {
			distanceText = "많이멀리";
		} else if ( distance < 3000 ) {
			distanceText = "많이멀리";
		} else {
			distanceText = "매우많이멀리";
		}

		return distanceText;
	},

	test: function(name) {
		alert(name);
	}
}