// ----------------------------------------
// @ 기본 지도 정보
// ----------------------------------------
function MapInfo(){ 
	this.mapObj = null;
	this.width = 600;
	this.height = 400;
	this.level = 1;
	this.initXPoint = 0;
	this.initYPoint = 0;

	this.mapPointURL = "./xmlMapPointData.php";
	this.isAdmin = false;
	this.gubun = "";
}
// 지도를 ZOOM(IN/OUT)을 한다.
MapInfo.prototype.setZoom = function ( arg1 ) {
	this.mapObj.setZoom(arg1);
	MAIN("go_marking");
};
// 지도를 ZOOM IN을 한다.
MapInfo.prototype.zoomIn = function () {
	this.mapObj.zoomIn();
	MAIN("go_marking");
};
// 지도를 ZOOM OUT을 한다.
MapInfo.prototype.zoomOut = function () {
	this.mapObj.zoomOut();
	MAIN("go_marking");
};
// 기본파라메터를 가져온다.
MapInfo.prototype.getMapParamData = function () {
	var param = new String();

	 param += "&moveX="+mapInfo.mapObj.upea5.x;
	 param += "&moveY="+mapInfo.mapObj.upea5.y;
	 param += "&khc9Width="+mapInfo.mapObj.st7.width;
	 param += "&khc9Height="+mapInfo.mapObj.st7.height;
	 param += "&width="+mapInfo.mapObj.hev8.jz0.width;
	 param += "&height="+mapInfo.mapObj.hev8.jz0.height;

/*
	 param += "&moveX="+mapInfo.mapObj.asb2.x;
	 param += "&moveY="+mapInfo.mapObj.asb2.y;
	 param += "&khc9Width="+mapInfo.mapObj.g3.width;
	 param += "&khc9Height="+mapInfo.mapObj.g3.height;
	 param += "&width="+mapInfo.mapObj.hrej9.g1.width;
	 param += "&height="+mapInfo.mapObj.hrej9.g1.height;
*/	 

/*
	param += "&moveX="+mapInfo.mapObj.ixu7.x;
	param += "&moveY="+mapInfo.mapObj.ixu7.y;
	param += "&khc9Width="+mapInfo.mapObj.khc9.width;
	param += "&khc9Height="+mapInfo.mapObj.khc9.height;
	param += "&width="+mapInfo.mapObj.euk7.gsvi7.width;
	param += "&height="+mapInfo.mapObj.euk7.gsvi7.height;
*/
	//param = "x=310216&y=552072&level=2&moveX=1211&moveY=2157&khc9Width=268&khc9Height=290&width=68&height=-86&gubun=map_point&isAdmin=true";

	return param;
};
// 기본 지도를 그린다.
MapInfo.prototype.setMapData = function ( objmsg ) {
	this.width = objmsg.width==null?this.width:objmsg.width;
	this.height = objmsg.height==null?this.height:objmsg.height;
	this.level = objmsg.level==null?this.level:objmsg.level;

	this.mapObj = new NMap(document.getElementById('mapContainer'),this.width,this.height);
	this.mapObj.setCenterAndZoom(new NPoint(objmsg.xPoint,objmsg.yPoint),this.level);
	
	this.initXPoint = objmsg.xPoint;
	this.initYPoint = objmsg.yPoint;

	//@.
	this.mapPointURL = objmsg.mapPointURL==null?this.mapPointURL:objmsg.mapPointURL;
	this.gubun = objmsg.gubun==null?this.gubun:objmsg.gubun;
	this.isAdmin = objmsg.isAdmin==null?this.isAdmin:objmsg.isAdmin;
};
// ZOOM 컨트롤 추가
MapInfo.prototype.addZoomControl = function () {
	var zoom = new NZoomControl();
	zoom.setAlign("right");
	zoom.setValign("bottom");
	
	this.mapObj.addControl(zoom);
};
// 이벤트 Key 등록
MapInfo.prototype.addEventKeyControl = function (mode) {
	switch(mode){
		case "010": // 지도포인트 등록기에서 호출
			NEvent.addListener(this.mapObj,"click",eventClick);
			NEvent.addListener(this.mapObj,"mousedown",eventRbtClick);
			NEvent.addListener(this.mapObj,"endDrag",this.eventEndDrag);
			break;
		case "020": // 버스노선정보에서 호출
			NEvent.addListener(this.mapObj,"endDrag",this.eventEndDrag);
			break;
		default:
			NEvent.addListener(this.mapObj,"endDrag",this.eventEndDrag);
			break;
	}
};
/**
 * 마우스 드래그가 끝날떄 실행 함수
 */
MapInfo.prototype.eventEndDrag = function (pos) {
	try{
		var xPoint = mapInfo.initXPoint;
		var xX = pos[0];
		var yPoint = mapInfo.initYPoint;
		var yY = pos[1];

		if(    ( (xX - (0)) <= (xPoint + 0)  && (xPoint + 0) <= (xX + (0)) )
			&& ( (yY - (0)) <= (yPoint + 0)  && (yPoint + 0) <= (yY + (0)) ) )
		{
		}else{
			mapInfo.initXPoint = xX;
			mapInfo.initYPoint = yY;

			// 지도에 마킹한다.
			var d = document.data;
			var param = "x="+xX;
			param += "&y="+yY;
			param += "&level="+mapInfo.mapObj.getZoom();
			param += mapInfo.getMapParamData();
			param += "&gubun="+mapInfo.gubun;
			param += "&isAdmin="+mapInfo.isAdmin;
			var url = mapInfo.mapPointURL;
			var method = "go_marking"; 
			//alert(url+"?"+param);
			AJAX_MAP_INIT( url, param, method ); 
		}
	}catch(e){alert(e);}
};
// ----------------------------------------
// @ 지도에 마킹하기
// ----------------------------------------
function MapMarkInfo(){
	this.infowin1 = new NInfoWindow();
}
// 해당 위치에 title를 뿌린다.
MapMarkInfo.prototype.setMarkingPoint = function ( objmsg ) {
	var mapObj = objmsg.mapObj;
	var key = objmsg.key==null?"":objmsg.key;
	var xPos = objmsg.xPos;
	var yPos = parseInt(objmsg.yPos) - 15;
	var level = objmsg.level;
	var title = objmsg.title.replace(/ /g, '&nbsp;');				// 공백을 치환하여 보여준다.
	var isDel = objmsg.isDel==null?"false":objmsg.isDel;
	var script = objmsg.script==null?"false":objmsg.script;
	 
	// 해당 포인트로 이동한다.
	//mapObj.setCenterAndZoom(new NPoint(xPos,yPos),level);

	var _html = new String();
	//_html += "<table border=0 cellpadding=2 cellspacing=0 bgcolor=#04B5C2 style='border:2px #01838C solid'>";	
	/*
	_html += "<table border=0 cellpadding=0 cellspacing=0 bgcolor=#FFFFFF>";	
	_html += "<tr><td nowrap height='1'></td></tr>";	
	_html += "<tr><td nowrap style='font-family:굴림;font-size:9pt;color:#000000'><b>"+title+"</b></td></tr>";	
	_html += "</table>";
	*/
	_html = "";
	_html += "<span style=\"background-color:#FFFFFF;\">";
	_html += title;
	_html += "</span>";
	
	// 해당 포인트에 title를 뿌린다.
	var loc_Point = new NPoint(xPos,yPos);
	var infowin1 = new NInfoWindow();
	mapObj.addOverlay(infowin1,key);
	infowin1.redrawCallback = null;
	infowin1.opacity = 1;

	infowin1.setAutoPosX(false);
	infowin1.setAutoPosY(false);
	infowin1.set(loc_Point,_html);
	infowin1.showWindow();
};
// 해당 위치에 title를 지운다.
MapMarkInfo.prototype.delMarkingPoint = function ( objmsg ) {
	var mapObj = objmsg.mapObj;
	mapObj.removeOverlay(this.infowin1);

	this.infowin1 = new NInfoWindow();
};
// 해당 위치에 포인트 이미지를 마킹한다.
MapMarkInfo.prototype.setMarkingPointType = function ( objmsg ) {
	var mapObj = objmsg.mapObj;
	var xPos = objmsg.xPos;
	var yPos = objmsg.yPos;

	var loc_Point = new NPoint( parseInt(xPos)+20, parseInt(yPos)+10);
	var icon = new NIcon('http://map.utravelnote.com/images/pointType'+objmsg.pointTypeCode+'.gif', new NSize(26,26));
	var infowin  = new NInfoWindow();
	mapObj.addOverlay(infowin);

	var map_mark = new NMark(loc_Point,icon);
	NEvent.addListener(map_mark,"mouseover",
							function(loc_Point){
								infowin.set(loc_Point,"<table border=0 cellpadding=2 cellspacing=0 bgcolor=#99FF99 style='border:2px #009900 solid'><tr><td nowrap height='1'></td></tr><tr><td nowrap style=font-family:굴림;font-size:9pt>"
														+ objmsg.title.replace(/\./gi, '')
														+ "</td></tr></table>");
								infowin.showWindow()
							}
						);
	NEvent.addListener(map_mark,"mouseout", 
							function(){ 
								infowin.hideWindow(); 
							}
						);
	NEvent.addListener(map_mark,"click" , 
							function(){
								/*이곳에 클릭시 이동할 스크립트를 넣어시오~~*/
								if (objmsg.aKey) {
									if (opener) {
										opener.location.href='http://www.utravelnote.com/hotel/' + objmsg.aKey;
										window.close();
									}
								} 
							}
						);
	mapObj.addOverlay(map_mark);
};
