/********************************************************************************************/
/* NaverMap
/*
/* 설명: 웹페이지의 사용자가 지정한 레이어에 네이버 맵을 표시합니다.
/*
/* 조건: 먼저 맵을 위한 레이어를 웹페이지에 생성해야 하며, 네이버 자바스크립트를 include 해야함.
/*
/*    예) <SCRIPT LANGUAGE="JavaScript" src="http://maps.naver.com/js/naverMap.naver?key=7bcd03e2f64ce9a472f567d9cdc6e67e"></SCRIPT>
/*
/*
/* 생성: new 연산자로 오브젝트 생성
/*
/*    예) var nmap    = new NaverMap();
/*        nmap.initNmap(document.getElementById('mapContainer'), 686, 396);
/*
/* 제작 : 2008-01-03 hamani
/*
/********************************************************************************************/

NaverMap = function() {
	this.mapObj;			// 네이버맵 초기화
	this.mapZoom;			// 지도 확대값
	this.mapPoint;			// 좌표 클래스
	this.mapZoomCtl;		// 줌컨트롤을 표시하기 위한 클래스
	this.mapSaveBtn;		// 수평,수직 좌표값을 표시하기 위한 클래스

	this.focusimg;			// 중심점에 표시할 이미지
	this.infowin;			// 짧은설명(마우스오버때)
	this.infowin0;			// 상세설명(클릭시 팝업창)
}
NaverMap.prototype = {
	initNmap: function(obj,x,y) {			// 초기설정: 맵생성, 설명창생성
		this.mapZoom = 3;
		this.mapPoint = new NPoint(0,0);
		this.mapObj = new NMap(obj,x,y);		// 네이버맵 초기화

		this.infowin = new NInfoWindow();		// 간단설명
		this.infowin.setZIndex(190);
		this.infowin.setOpacity(0.6);
		this.infowin.setOffset(new NSize(-10,17))
		this.infowin.setPos(new NPoint(1,-1.01));

		this.infowin0 = new NInfoWindow();		// 상세설명
		this.infowin0.setZIndex(200);
		this.infowin0.setAutoPosX(false);
		this.infowin0.setAutoPosY(false);
		this.infowin0.setOffset(new NSize(-10,10))
		this.infowin0.setPos(new NPoint(1,-1.1));

		this.mapObj.addOverlay(this.infowin);
		this.mapObj.addOverlay(this.infowin0);
		//this.infowin.showWindow();

		this.focusimg = new Array();
		this.focusimg[1] = new NIcon('http://www.the5.com/img/map_bd.gif', new NSize(62,68));
		//this.focusimg[2] = new NIcon('http://www.the5.com/img/map_add.gif', new NSize(161,58));
		this.focusimg[2] = new NIcon('http://www.the5.com/img/map_add2.png', new NSize(229,54));
	},
	setZoomLevel: function(n) {
		this.mapZoom = n;
	},
	setPosition: function(xpos,ypos) {				// 좌표를 화면 중앙으로 해서 맵을 표시
		this.mapPoint.set(xpos,ypos);
		this.mapObj.setCenterAndZoom(this.mapPoint, this.mapZoom);
	},
	getPosition: function() {
		return this.mapObj.getCenter().toString();
	},
	moveMap: function(x, y) {
		var nowPoint = this.mapObj.getCenter();
		var x_dist = x-nowPoint.x;
		var y_dist = y-nowPoint.y;
		var zoom = this.mapObj.getZoom();
		zoom = 1 << (zoom-1);
		this.mapObj.pan(x_dist/zoom, y_dist/zoom);
	},
	setZoomControl: function(xpos,ypos) {
		this.mapZoomCtl = new NZoomControl();
		this.mapZoomCtl.setAlign(xpos);
		this.mapZoomCtl.setValign(ypos);
		this.mapObj.addControl(this.mapZoomCtl);
	},
	setSaveControl: function(xpos,ypos) {
		this.mapSaveBtn = new NSaveBtn();
		this.mapSaveBtn.setAlign(xpos);
		this.mapSaveBtn.setValign(ypos);
		this.mapObj.addControl(this.mapSaveBtn);
	},
	setMainImage: function(url,x,y) {
		this.focusimg = new NIcon(url,new NSize(x,y));
	},
	addClickEvent: function(func) {
		NEvent.addListener(this.mapObj,"click",func);
	},
	removeClickEvent: function(func) {
		NEvent.removeListener(this.mapObj,"click",func);
	},
	showFocusImage: function(x,y,stype,fover,fout,fclick) {
		var point  = new NPoint(x,y);
		var marker = new NMark(point,this.focusimg[stype]);
		NEvent.addListener(marker,"mouseover", fover);
		NEvent.addListener(marker,"mouseout", fout);
		NEvent.addListener(marker,"click", fclick);
		this.mapObj.addOverlay(marker);
		return marker;
	},
	hideFocusImage: function(mark) {
		this.mapObj.removeOverlay(mark);
	},
	showPointInfo: function(x,y,str) {
		this.infowin0.set(new NPoint(x,y),str);
		this.infowin0.showWindow();
	},
	hidePointInfo: function() {
		this.infowin0.hideWindow();
	},
	showShortInfo: function(x,y,str) {
		this.infowin.set(new NPoint(x,y),str);
		this.infowin.showWindow();
	},
	hideShortInfo: function() {
		this.infowin.hideWindow();
	}
}