/**
* MapApplication - 지도 어플리케이션 클래스
* 
*/
var MapApplication = function(options){
	daum.extend(this, options || {});

	this.Icons = MapApplication.Icons;
	daum.maps.DRoadView.Controller.documentTitle = "Daum 플레이스";
	this.placeMarkers = [];
	if(this.radios) this.initRadios();
};
MapApplication.Icons = {
	"PLACE_CENTER" : new DIcon("http://i1.daumcdn.net/localimg/life/images/detail/ico_life_tm2.png", new DSize(41, 57), new DPoint(-20, -57)),
	"PLACE_FOOD" : new DIcon("http://i1.daumcdn.net/localimg/life/images/detail/ico_tm1_off.png", new DSize(33, 45), new DPoint(-16, -45)),
	"PLACE_FOOD_ON" : new DIcon("http://i1.daumcdn.net/localimg/life/images/detail/ico_tm1_on.png", new DSize(33, 45), new DPoint(-16, -45)),
	"PLACE_GOOD" : new DIcon("http://i1.daumcdn.net/localimg/life/images/detail/ico_tm2_off.png", new DSize(33, 45), new DPoint(-16, -45)),
	"PLACE_GOOD_ON" : new DIcon("http://i1.daumcdn.net/localimg/life/images/detail/ico_tm2_on.png", new DSize(33, 45), new DPoint(-16, -45)),
	"PLACE_PUBLIC" : new DIcon("http://i1.daumcdn.net/localimg/life/images/detail/ico_tm3_off.png", new DSize(33, 45), new DPoint(-16, -45)),
	"PLACE_PUBLIC_ON" : new DIcon("http://i1.daumcdn.net/localimg/life/images/detail/ico_tm3_on.png", new DSize(33, 45), new DPoint(-16, -45)),
	"PLACE_FOOD_WITH_LINE" : new DIcon("http://i1.daumcdn.net/localimg/life/images/detail/ico_tm1_off.png", new DSize(33, 45), new DPoint(-16, -45)),
	"PLACE_FOOD_WITH_LINE_ON" : new DIcon("http://i1.daumcdn.net/localimg/life/images/detail/ico_tm1_on.png", new DSize(33, 45), new DPoint(-16, -45)),
	"PLACE_GOOD_WITH_LINE" : new DIcon("http://i1.daumcdn.net/localimg/life/images/detail/ico_tm2_off.png", new DSize(33, 45), new DPoint(-16, -45)),
	"PLACE_GOOD_WITH_LINE_ON" : new DIcon("http://i1.daumcdn.net/localimg/life/images/detail/ico_tm2_on.png", new DSize(33, 45), new DPoint(-16, -45)),
	"PLACE_ACCOMMO_WITH_LINE" : new DIcon("http://i1.daumcdn.net/localimg/life/images/detail/ico_tm3_off.png", new DSize(33, 45), new DPoint(-16, -45)),
	"PLACE_ACCOMMO_WITH_LINE_ON" : new DIcon("http://i1.daumcdn.net/localimg/life/images/detail/ico_tm3_on.png", new DSize(33, 45), new DPoint(-16, -45)),
	"PLACE_NUMBER" : Life.Templates.placeNumberIcon,
	"PLACE_NUMBER_ON" : Life.Templates.placeNumberIconOn,
	"PLACE_SMALL" : new DIcon("http://i1.daumcdn.net/localimg/life/images/top/ico_t_mappoint.png", new DSize(21, 21), new DPoint(-10, -10)),	
	"PLACE_WINDOW" : Life.Templates.placeWindow,
	"PLACE_WINDOW_PHOTO" : Life.Templates.placeWindowPhoto,
	"PLACE_WINDOW_DETAIL" : Life.Templates.placeWindowDetail,
	"PLACE_WINDOW_DETAIL_NOCOMMENT" : Life.Templates.placeWindowDetailNoComment,
	"PLACE_CENTER_MARK" : Life.Templates.placeCenterMark
};
MapApplication.prototype = {	
	mapOptions : {
		scrollWheelable : false,
		coordinate : "wcongnamul",
		shortLogo : true,
		logoImage : false,
		reduced_scale : false,
		infoWindowPanTo : true,		
		proxyservice : "/life/api/ProxyServiceAPI.do?goUrl=",
		map_type : "TYPE_MAP"
	},
	
	reset : function(options){
		daum.extend(this, options || {});
		for(var i=0,loop=this.placeMarkers.length; i<loop; i++){
			this.placeMarkers[i].destroy();
		}
		
		this.setMarks();
	},
	
	initRadios : function(){
	
	},
	
	setMap : function(panel, options){
		var mapOptions = {};
		daum.extend(mapOptions, this.mapOptions);
		daum.extend(mapOptions, options || {});
		
		this.maps = new DMap(panel, mapOptions);
		
		this.maps.disabledMapType("ROADVIEW");
		this.maps.disabledMapType("REALTRAFFIC");
		
		this.MapControls = {
			ZoomControl : new DZoomControl(),
			TypeControl : new DMapTypeControl()
		};
		
		this.maps.addControl(this.MapControls.TypeControl);		
		this.maps.addControl(this.MapControls.ZoomControl);
		
		var topArea = this.maps.main.tools.controlAlign.top.right.element;
		var typeArea = this.maps.main.tools.topMapTypeArea;
		
		if(this.type == "place"){
			daum.Element.setTop(topArea, 46);		
			daum.Element.setWidth(topArea, 22);
			daum.Element.setTop(typeArea, 46);
			typeArea.style.right = "38px";				
		}else{
			daum.Element.setTop(topArea, 9);			
			typeArea.style.right = "38px";
		}
	},
	
	setCenter : function(point, level){
		if(this.centerMark){
			this.centerMark.destroy();	
		}
		if(this.data && this.data.summary == "") this.data.summaryshort = "&nbsp;";
		
		if(this.type == "place"){
			var placeMarkerTemplate = TrimPath.parseTemplate(MapApplication.Icons["PLACE_CENTER_MARK"]);
			var placeIcon = placeMarkerTemplate.process({
				placeurl : this.data.placeurl,
				photourl : this.data.photourl					
			});
		}else{
			var placeIcon = MapApplication.Icons["PLACE_CENTER"];
		}
		
		this.centerMark = new PlaceMarker(point, {
			data : this.data,
			icon : placeIcon,
			iconOffset : new DPoint(-41,-87),
			zindex : 10,
			baseLevel : 4,
			type : this.type,
			placeCenter : true,
			placeWindowTemplate : MapApplication.Icons["PLACE_WINDOW_PHOTO"],
			templateOffset : new DPoint(-131, -141)
		});

		this.centerMark.drawMark(this.maps, this.type);
		
		if(this.type == "place"){
			var scale = daum.maps.MAP_SCALE["wcongnamul"][level];
			var otherCoords = this.maps.main.coordinate.getOtherCoord(this.maps.getCenter(), this.maps.main.coordinate.screenSize, scale);
			var p = MapApplication.getPixByCoordPoint(this.maps.main, point, scale, otherCoords);
			p.y -= 40;
			p = MapApplication.getCoordByPixPoint(this.maps.main, p, scale, otherCoords);
			this.maps.setCenter(p, level);
			
			//this.centerMark.onMarkClick();
		}else{
			this.maps.setCenter(point, level);
		}
	},
	
	setBound : function(points){
		if(!points || points.length == 0) return;

		var minP = points[0].clone(), maxP = points[0].clone();
		for(var i=0,loop=points.length; i<loop; i++){
			minP.x = Math.min(minP.x, points[i].x);
			minP.y = Math.min(minP.y, points[i].y);
			maxP.x = Math.max(maxP.x, points[i].x);
			maxP.y = Math.max(maxP.y, points[i].y);
		}
		
		this.setBound2(minP.x, minP.y, maxP.x, maxP.y);
	},
	
	setBound2 : function(left,bottom,right,top){
		var pxSize = this.maps.getSize();
		var gapX = right - left;
		var gapY = top - bottom;
		
		//level 5를 기준으로 계산 (level 5가 pixel*10이 w좌표이기 때문에 계산 편이상)
		var xLevel = Math.ceil( Math.log(gapX/(pxSize.width*10))/Math.log(2));
		var yLevel = Math.ceil( Math.log(gapY/(pxSize.height*10))/Math.log(2));
		var maxLevel = (xLevel>yLevel)?xLevel:yLevel;
		this.maps.setCenter( new DPoint((left+right)/2,(bottom+top)/2), 5+maxLevel);
	},
	
	setMarks : function(){
		 if(!this.placedatas) return false;
		 
		 var data = this.placedatas;
		 
		 this.placeMarkers = [];
		 
		 for(var i=0,loop=data.length; i<loop; i++){
		 	var pm = new PlaceMarker(data[i].point, { "data" : data[i], icon : MapApplication.Icons[data.placeType], type : this.type });
		 	this.placeMarkers.push(pm);
		 	pm.drawMark(this.maps);
		 }		 
	},
	
	clear : function(){
		this.maps.clearOverlay();		
	}
};
/**
* MapApplication Utils
*/
MapApplication.getPixByCoordPoint = function(mapmain, dp, scale, otherCoord, type){
	var type = type || mapmain.BASIC_COORDINATE_TYPE;
		
	if(type != mapmain.BASIC_COORDINATE_TYPE) {
		var p = mapmain.coordinate.getTransCoord(dp, type, mapmain.BASIC_COORDINATE_TYPE);	
	}else{
		var p = dp;
	}
	
	return new DPoint(Math.round((p.x - otherCoord.minPoint.x) / scale), Math.round((otherCoord.maxPoint.y - p.y) / scale));
};	
MapApplication.getCoordByPixPoint = function(mapmain, dp, scale, otherCoord, type){		
	var type = type || mapmain.BASIC_COORDINATE_TYPE;
	
	dp.y = mapmain.coordinate.screenSize.height - dp.y;
	
	var congx = (otherCoord.minPoint.x + dp.x * scale);
	var congy = (otherCoord.minPoint.y + dp.y * scale);
	
	if(type != mapmain.BASIC_COORDINATE_TYPE){
		return mapmain.coordinate.getTransCoord(new DPoint(congx, congy), mapmain.BASIC_COORDINATE_TYPE, type);
	} else {
		return new DPoint(congx, congy);
	}
};
/**
* PlaceMarker - MapApplication과 함께 돌아가는 장소 마킹 객체
*/
var PlaceMarker = function(point, options){
	this.point = point;
	
	this.options = {	
		icon : MapApplication.Icons["PLACE_CENTER"],
		placeWindowTemplate : MapApplication.Icons["PLACE_WINDOW"],
		coordinate : "wcongnamul",
		baseLevel : 3
	};
	
	daum.extend(this.options, options || {});
	
	if(this.options.placeWindowTemplate){
		this.template = TrimPath.parseTemplate(this.options.placeWindowTemplate);
	}
	this.type = this.options.type || "theme";
	
	this.createMark();	
};
PlaceMarker.prototype = {
	getPixByCoordPoint : MapApplication.getPixByCoordPoint,
	getCoordByPixPoint : MapApplication.getCoordByPixPoint,
	
	createMark : function(){
		var options = {
			mark : this.options.icon,
			coordinate : this.options.coordinate || "wcongnamul"
		};
		if(this.options.iconOffset) options.offset = this.options.iconOffset;
		if(this.options.zindex) options.zindex = this.options.zindex;
		if(this.options.focusable) options.focusable = this.options.focusable;
		
		this.mark = new DMark(this.point, options);
		
		return this.mark;
	},
	
	drawMark : function(map, type){
		map.addOverlay(this.mark);
		if(type!="place")
			DEvent.addListener(this.mark, "click", this.onMarkClick.bind(this));
		//this.onMarkClick();
	},
	
	onMarkClick : function(){		
		this.mark.hide();	
		
		if(!this.placeWindow){
			this.createPlaceWindow();			
			this.mark.main.overlay.addOverlay(this.placeWindow);
			if(!this.mark.main.placeWindows){
				this.mark.main.placeWindows = [];
			}
			
			this.mark.main.placeWindows.push(this);
		}
		var mainPlaceWindows = this.mark.main.placeWindows;
		for(var i=0,loop=mainPlaceWindows.length; i<loop; i++){
			if(mainPlaceWindows[i] !== this){
				mainPlaceWindows[i].placeWindow.hide();
				mainPlaceWindows[i].mark.show();
			}
		}
		this.placeWindow.show();
		
		var scale = daum.maps.MAP_SCALE["wcongnamul"][this.options.baseLevel];
		var otherCoord = this.mark.main.coordinate.getOtherCoord(this.mark.main.getCenter(), this.mark.main.coordinate.screenSize, scale);
	
		var panpoint = this.getPixByCoordPoint(this.mark.main, this.mark.point, scale, otherCoord);
		panpoint.y -= (this.options.placeCenter) ? 140 : 90;
		panpoint = this.getCoordByPixPoint(this.mark.main, panpoint, scale, otherCoord);				

		if(this.mark.main.coordinate.getLevel() != this.options.baseLevel && this.type != "place"){			
			this.mark.main.setCenter(panpoint, this.options.baseLevel);
		}else{
			if(this.mark.main.coordinate.isBound("map", panpoint, this.mark.main.coordinateType, "extend") || this.type == "place"){
				this.mark.main.panTo(panpoint.x, panpoint.y, "wcongnamul");
			}else{
				this.mark.main.setCenter(panpoint, this.options.baseLevel);
			}					
		}
		
		this.onMapClickObserver = DEvent.addListener(this.mark.main, "click", this.hidePlaceWindow.bind(this));		
	},
	
	createPlaceWindow : function(){		
		this.placeWindow = new DMark(this.mark.point, {
			mark : this.template.process(this.options.data),
			offset : this.options.templateOffset || new DPoint(-96, -121),
			clickable : false,
			zindex : 1000,
			focusable : true
		});
		
		try{daum.$$("button.close", this.placeWindow.panel)[0].onclick = this.hidePlaceWindow.bind(this);}
		catch(e){};
	},
	
	hidePlaceWindow : function(){
		try{
			this.mark.show();
			this.placeWindow.hide();
			DEvent.removeListener(this.mark.main, "click", this.onMapClickObserver);
		}catch(e){}
	},
	
	destroy : function(){
		if(this.placeWindow) this.placeWindow.destroy();
		
		DEvent.removeListener(this.mark.main, "click", this.onMapClickObserver);
		
		this.mark.destroy();
	}
};
/**
* DMapTypeControl - 라이프 맵타입컨트롤
*/
daum.maps.DMapTypeControl = function(){
	this.$super();
	
	this.panel; 
	this.subPanel; 
	this.hybridp;
	
	this.ul_panel ;
	this.checkbox; 
	
	this.align = "right";
	this.valign = "top";
	this.close_timer = null;
	this.main2 ; 
	this.menuList;

	this.realCurType;
	this.curType; 	 
	this.skyview; 
	this.init();
	
	this.e_handler1;
	this.e_handler2;  
	this.e_handler3;
	this.e_handler4;  	
};
daum.Function.inherit(daum.maps.DMapTypeControl, daum.maps.DControl);
daum.Function.members(daum.maps.DMapTypeControl, {
	name : "MapTypeControl",

	title : ['지도 보기 ', '스카이뷰  보기 ', '로드뷰', '교통정보 '],
	
	init : function(){
		this.addInitFunction(this._setMapClient);
		this.imagePreLoad();
		this._createControl();
	},
 
	_setMapClient : function(){
		this.main2 = this.main; 
 	 	var cTabList = this.main.TypeMenu;
 	 	var IsEnabledBtn = this.main.isTypeMenu;
 
 	 	var cMapType = this.main.options.map_type;
  	 	var cAttribute = this.main.options.map_attribute;
  	 	var menuType; 
  	 	this._createLi();
  	 	
  	 	this.bindDEvent();
 	},
 	
 	bindDEvent : function(){
 		daum.createBindFunction(this._setMapChanged, this);
 		daum.createBindFunction(this._setMapAttrChanged, this);
 		
		DEvent.addListener(this.main, 'mapchanged', this._setMapChanged.Binded);
		DEvent.addListener(this.main, 'changed', this._setMapAttrChanged.Binded);
 	},

	_setMapAttrChanged : function(type){
		this._setMapChanged(this.main.options.map_type);
	}, 
	
	_setMapChanged : function(){
		this._createLi();
 		if( this.main2.options.logo ){
			this.main2.changeCopylight();
		}
		if(this.main2.options.reduced_scale ){
			this.main2.changeReducedScale();
		}
	},

	_createLi : function(main){
 	 	var cTabList = this.main2.TypeMenu;
 	 	var IsEnabledBtn = this.main2.isTypeMenu;
 	 	var cMapType = this.main2.options.map_type;
  	 	var cAttribute = this.main2.options.map_attribute;
	    //var template = new daum.Template("<li style='margin:0;padding:0;list-style:none;z-index:0;height:23px;float:left;'></li>");
	    var template = document.createElement("li");
	    daum.Element.setCssText(template, "margin:0;padding:0;list-style:none;z-index:0;height:20px;float:left;display:inline;");
 
  	 	//var url = "http://i1.daumcdn.net/localimg/localimages/07/2008/map/new/";
  	 	var url = "http://i1.daumcdn.net/localimg/life/images/detail/";
		var w = 251;
 	 	for( var i=0; i<4 ; i++ ){ //cTypeList.length
	 		if(cTabList[i] == "ROADVIEW" && IsEnabledBtn[cTabList[i]] == false){
	 			w = w - 55;
 	 		}
	 		if(cTabList[i] == "REALTRAFFIC" && IsEnabledBtn[cTabList[i]] == false){
	 			w = w - 55;
 	 		}
 	 	}
 	  	this.ul_panel.style.width = w + 'px';

  	 	this.ul_panel.innerHTML = "";
  	 	
 	 	for( var i=0; i<4 ; i++ ){ //cTypeList.length
 	 		
 	 		if(IsEnabledBtn[cTabList[i]] == true){
				//var liElement = template.toElement();
 	 			var liElement = template.cloneNode(true);	
				this.ul_panel.appendChild(liElement);
				if( i== 0){
					if( cMapType == "TYPE_MAP"){
						daum.Element.setPngOpacity(liElement, url + "bt_life_tm_map_o.png");
						liElement.style.cursor = 'default';
					}else{
						daum.Element.setPngOpacity(liElement, url + "bt_life_tm_map.png");
					}
					liElement.style.width = "54px"
				}else if( i== 1){
					
					if( cMapType == "TYPE_SKYVIEW"){
						
						liElement.style.backgroundImage="url("+url + "bt_life_new_sky_o.png)";
						liElement.style.backgroundPosition="0px -7px";
						$('skyview_top').className="skyBtnAdd_o";
					
					}else{
						liElement.style.backgroundImage="url("+url + "bt_life_new_sky.png)";
						liElement.style.backgroundPosition="0px -7px";
						$('skyview_top').className="skyBtnAdd";
					
					}
					this.ul_panel.appendChild(liElement);
				//	this.ul_panel.appendChild(addliElement);
					liElement.style.width = "87px"
	 				this.skyview = liElement;
					liElement.setAttribute('id', 'id_skyview');
	 			}else if( i== 2){
	 				
	 				if( IsEnabledBtn["REALTRAFFIC"] == false ){
						if( cAttribute == "ROADVIEW"){
							daum.Element.setPngOpacity(liElement, url + "bt_life_tm_road_o.png");
						}else{
							daum.Element.setPngOpacity(liElement, url + "bt_life_tm_road.png");
						}
	 				}else{
						if( cAttribute == "ROADVIEW"){
							daum.Element.setPngOpacity(liElement, url + "bt_life_tm_road_o.png");
							
						}else{
							daum.Element.setPngOpacity(liElement, url + "bt_life_tm_road.png");
							
						}
	 				}
					liElement.style.marginLeft = "4px";
					liElement.style.width = "55px"
 
	 			
	 			}else if( i== 3){
	 				if( IsEnabledBtn["ROADVIEW"] == false ){
						if( cAttribute == "REALTRAFFIC"){
							daum.Element.setPngOpacity(liElement, url + "bt_life_tm_road_o.png");
						}else{
							daum.Element.setPngOpacity(liElement, url + "bt_life_tm_road.png");
						}
	 				}else{	 			
						if( cAttribute == "REALTRAFFIC"){
							daum.Element.setPngOpacity(liElement, url + "bt_life_tm_road_o.png");
						}else{
							daum.Element.setPngOpacity(liElement, url + "bt_life_tm_road.png");
						}
					}	
					liElement.style.width = "55px"
	 			}
	 			
				liElement.menu_type = cTabList[i];
				liElement.idx = i; 	 			
				liElement.setAttribute('title', this.title[i]);
			 	this._bind_event(liElement);
 	 		} 
 		}
 		delete template; template = null;
	}, 
	
	_changeMapType : function(type){
		this._createLi();
	

		if( type != "M_SKYVIEW" &&  type != "M_SKYVIEW_ROADVIEW" ){
			this.removeObserver("e_handler1", "e_handler2");				
		}
	},
	click : function(e){
		var e = e || window.event;
		var element = e.srcElement || e.target;		
		var menutype = element.menu_type;
		var cur_idx = element.idx; //0, 1, 2, 3
		var bhybrid;
		if( (cur_idx ==0 && this.main.options.map_type == "TYPE_MAP") || (cur_idx == 1 && this.main.options.map_type == "TYPE_SKYVIEW") ){
			if(cur_idx == 1 && this.main.options.map_type == "TYPE_SKYVIEW"){
		
				this._changeHybridOption( this.main.options.map_hybrid ); 
			}
			return;
		}
		var cur_maptype = this.getCurMapType(this.main, cur_idx) ;

		if( this.main.options.map_type == "TYPE_MAP" ){
 			bhybrid =  false;
		}else{
			if( this.main.options.map_hybrid == true){
				this.checkbox.chkType = true;
				bhybrid = true  ;
			}else{
				this.checkbox.chkType = false;
				bhybrid = false  ;			
			} 	
		}
		 
  		var tools = this.main.tools;
 		var pre = this._createTypeObject( this.main.options.map_type, this.main.options.map_attribute, this.main.options.map_hybrid );
 		this.setMainOption( cur_maptype );
		var nxt = this._createTypeObject( this.main.options.map_type, this.main.options.map_attribute, this.main.options.map_hybrid ); 

 		if( pre.map_type !=  nxt.map_type ){
 			DEvent.fireEvent(this, "changed", pre, nxt);
 		}
 		DEvent.fireEvent(this, "changed", pre, nxt);		
		this._changeMapType(cur_maptype);
		
		return false;
	},
	
	setMainOption : function(cur_maptype){
		
		var mainMapType = {};
		if( cur_maptype == "M_MAP" ){
//			this.main.options.map_type = "TYPE_MAP";
//			this.main.options.map_attribute = "DEFAULT";
//			this.main.options.map_hybrid = false; 
			mainMapType.map_type = "TYPE_MAP";
			mainMapType.map_attr = "DEFAULT";
			mainMapType.map_hybrid = false;
		}else if( cur_maptype == "M_MAP_ROADVIEW"){
//			this.main.options.map_type = "TYPE_MAP";
//			this.main.options.map_attribute = "ROADVIEW";
//			this.main.options.map_hybrid = false; 			
			mainMapType.map_type = "TYPE_MAP";
			mainMapType.map_attr = "ROADVIEW";
			mainMapType.map_hybrid = false;
		}else if( cur_maptype == "M_SKYVIEW"){
//			this.main.options.map_type = "TYPE_SKYVIEW";
//			this.main.options.map_attribute = "DEFAULT";
//			this.main.options.map_hybrid =  this.checkbox.chkType ;
			mainMapType.map_type = "TYPE_SKYVIEW";
			mainMapType.map_attr = "DEFAULT";
			mainMapType.map_hybrid =  this.checkbox.chkType ;
		}else if( cur_maptype == "M_SKYVIEW_ROADVIEW"){
//			this.main.options.map_type = "TYPE_SKYVIEW";
//			this.main.options.map_attribute = "ROADVIEW";			
//			this.main.options.map_hybrid =  this.checkbox.chkType ;	
			mainMapType.map_type = "TYPE_SKYVIEW";
			mainMapType.map_attr = "ROADVIEW";			
			mainMapType.map_hybrid =  this.checkbox.chkType ;
		}else if( cur_maptype == "M_SKYVIEW_TRAFFIC"){
//			this.main.options.map_type = "TYPE_SKYVIEW";
//			this.main.options.map_attribute = "REALTRAFFIC";			
//			this.main.options.map_hybrid =  this.checkbox.chkType ;	
			mainMapType.map_type = "TYPE_SKYVIEW";
			mainMapType.map_attr = "REALTRAFFIC";			
			mainMapType.map_hybrid =  this.checkbox.chkType ;
		}else if( cur_maptype == "M_MAP_TRAFFIC"){
//			this.main.options.map_type = "TYPE_MAP";
//			this.main.options.map_attribute = "REALTRAFFIC";			
//			this.main.options.map_hybrid = false;	
			mainMapType.map_type = "TYPE_MAP";
			mainMapType.map_attr = "REALTRAFFIC";			
			mainMapType.map_hybrid = false;
		}		
		this.main.setMapType(mainMapType);
	},
	 
	getCurMapType : function(main, cur_idx){
		var cur_maptype; 
		if( main.options.map_type == "TYPE_MAP" ){
			if( main.options.map_attribute=="ROADVIEW"){
				if( cur_idx == 1){
					cur_maptype = "M_SKYVIEW_ROADVIEW";  
				}else if( cur_idx == 2){
					cur_maptype = "M_MAP"; 
				}else if(cur_idx == 3){
					cur_maptype = "M_MAP_TRAFFIC"; 
				}
			}else if( main.options.map_attribute=="REALTRAFFIC"){
				if( cur_idx == 1){
					cur_maptype = "M_SKYVIEW_TRAFFIC"; 
				}else if( cur_idx == 2){
					cur_maptype = "M_MAP_ROADVIEW"; 
				}else if(cur_idx == 3){
					cur_maptype = "M_MAP";  
				}
			}else{
				if( cur_idx == 1){
					cur_maptype = "M_SKYVIEW"; 
				}else if( cur_idx == 2){
					cur_maptype = "M_MAP_ROADVIEW";  
				}else if(cur_idx == 3){
					cur_maptype = "M_MAP_TRAFFIC"; 
				}
			}
		}else{
			if( main.options.map_attribute=="ROADVIEW"){
				if( cur_idx == 0){
					cur_maptype = "M_MAP_ROADVIEW";  
				}else if( cur_idx == 2){
					cur_maptype = "M_SKYVIEW";  
				}else if(cur_idx == 3){
					cur_maptype = "M_SKYVIEW_TRAFFIC";  
				}
			}else if( main.options.map_attribute=="REALTRAFFIC"){
				if( cur_idx == 0){
					cur_maptype = "M_MAP_TRAFFIC"; 
				}else if( cur_idx == 2){
					cur_maptype = "M_SKYVIEW_ROADVIEW"; 
				}else if(cur_idx == 3){
					cur_maptype = "M_SKYVIEW"; 
				}
			}else{
				if( cur_idx == 0){
					cur_maptype = "M_MAP"; 
				}else if( cur_idx == 2){
					cur_maptype = "M_SKYVIEW_ROADVIEW"; 
				}else if(cur_idx == 3){
					cur_maptype = "M_SKYVIEW_TRAFFIC"; 
				}
			}
  		}	
  		
  		return cur_maptype; 
	}, 
			 			
 	setAlign : function(align){
		this.align = align;
		this.main.tools.changeAlign(this, this.panel);
	}, 
	
	setValign : function(valign){
		this.valign = valign;
		this.main.tools.changeValign(this, this.panel);
	},	

	show : function(){
		this.panel.style.display = "block";
	}, 
	
	hide : function(){
		this.panel.style.display = "none";
	}, 	
	
	getObject : function(){
		return this.panel;
	},
 
	_createTypeObject : function(type, attr, hybrid){
 		var obj = new Object();
 		obj.map_type = type; 
 		obj.map_attr = attr;
 		obj.map_hybrid = hybrid; 
 		
 		return obj; 
	},
			
	imagePreLoad : function(){
		//var url = "http://i1.daumcdn.net/localimg/localimages/07/2008/map/new/";
		var url = "http://i1.daumcdn.net/localimg/life/images/detail/";
		this.preLoader = document.createElement("div");
		this.preLoader.innerHTML = '<img src="'+url+'bt_life_tm_map.png" /><img src="'+url+'bt_life_tm_map_o.png" /><img src="'+url+'bt_life_new_sky.png" /><img src="'+url+'bt_life_tm_sky_o.png" />'
		+ '<img src="'+url+'bt_life_tm_road.png" /><img src="'+url+'bt_life_tm_road_o.png" /><img src="http://i1.daumcdn.net/localimg/life/images/common/bt_box.gif" />';
		
		daum.HTMLFragment.appendChild(this.preLoader);
	},
			
	_createControl : function(){		
		try{			
			this.panel = document.createElement("div");
			daum.Element.setCssText(this.panel, "margin:0;padding:0;cursor:pointer;position:relative;z-index:10;");						
			var addliElement = document.createElement('div');
			daum.Element.setCssText(addliElement, "display:inline;position:absolute;top:-7px;left:-91px;width:30px;height:10px;z-index:1;");
			addliElement.id="skyview_top";
			addliElement.className="skyBtnAdd";
			this.panel.appendChild(addliElement);
			
			var outer = document.createElement("div");
			daum.Element.setCssText(outer, "margin:0;padding:0;position:absolute;left:-145px;-border:none;background:transparent;z-index:5;");			 
			outer.className="outer_ulPanel"
			this.panel.appendChild(outer);
			
			

 			this.ul_panel = document.createElement("ul");
 			daum.Element.setCssText(this.ul_panel, "overflow:hidden;margin:0;padding:0;clear:both;");
			outer.appendChild(this.ul_panel);
			
			this.hybridp = document.createElement("div");
			this.hybridp.id = "hybridp";
			daum.Element.setCssText(this.hybridp, "margin:0;padding:0;position:absolute;display:none;left:53px;top:20px;z-index:1000;width:83px;height:17px;border:2px solid #c00;background:#fff;padding:3px 0 0 1px;");
			outer.appendChild(this.hybridp);
			
			
			
 			this.checkbox = document.createElement("div");
 			daum.Element.setCssText(this.checkbox, "background:url(http://i1.daumcdn.net/localimg/life/images/common/bt_box.gif) no-repeat;background-position:0 -25px;height:14px;padding:2px 0 0 16px;font:11px dotum;letter-spacing:-1px;margin:0 0 0 6px;cursor:pointer;color:#444;");
			this.checkbox.chkType = true;
 			this.hybridp.appendChild(this.checkbox);
			
			var atag = document.createElement("a");
			atag.href = "#"; atag.innerHTML = "하이브리드";
			daum.Element.setCssText(atag, "margin:0;padding:0;color:#333;font:11px dotum;text-decoration:none;");			
			this.checkbox.appendChild(atag);

			//daum.Event.addEvent(this.checkbox, 'click', this._check_hybrid.bind(this));
			daum.Event.addEvent(this.checkbox, 'click', daum.Function.bind(this._check_hybrid, this));
			daum.Event.addEvent(atag, 'click', daum.preventDefault);
		 	daum.Event.addEvent(atag, 'focus', atag.blur);
		 	
		 	daum.Event.addEvent(this.hybridp, 'dblclick', daum.stopEvent);
		 	
		 	this.panel.eventDMapControls = true;
		}catch(e){
			console.debug(e.message);
		}
 	},
 	
 	_changeHybridOption : function( bool ){
		if( bool == true){
			this.checkbox.chkType = true;
			this.checkbox.style.backgroundPosition = "0 -25px";
		}else{
			this.checkbox.chkType = false;
			this.checkbox.style.backgroundPosition = "0 0";
		} 	 	
 	}, 
 	
 	_check_hybrid : function(e){
 		var e = e || window.event;
 		
 		var preMaptype;
 		var nxtMaptype;
 		this.checkbox.chkType = this.checkbox.chkType ? false : true;

		var pre = this._createTypeObject(this.main.options.map_type, this.main.options.map_attribute, this.main.options.map_hybrid);
 		if(this.checkbox.chkType == true ){
			this.checkbox.style.backgroundPosition = "0 -25px";
			this.main.options.map_hybrid = true;
		}else{
			this.checkbox.style.backgroundPosition = "0 0";
			this.main.options.map_hybrid = false;
		}
		var nxt = this._createTypeObject(this.main.options.map_type, this.main.options.map_attribute, this.main.options.map_hybrid);
		DEvent.fireEvent(this, "changed", pre, nxt);
		this.main.requestMap(0, true);
 	}, 
 	 	
 	_bind_event : function(eObj){
  		//daum.Event.addEvent(eObj, 'click', this.click.bindAsEventListener(this) );
  		this.defaultClickObserver = daum.Event.addEvent(eObj, 'click', daum.Function.bindAsEventListener(this.click, this));
  		if( eObj == this.skyview ){
  			//daum.Event.addEvent(eObj, 'click', this.hybrid_show.bindAsEventListener(this));
  			daum.Event.addEvent(eObj, 'click', daum.Function.bindAsEventListener(this.hybrid_show, this));
  		}else{
  			//daum.Event.addEvent(eObj, 'click', this.hybrid_hide.bindAsEventListener(this));
  			daum.Event.addEvent(eObj, 'click', daum.Function.bindAsEventListener(this.hybrid_hide, this));
  		}
  		
  		daum.Event.addEvent(eObj, 'mousedown', daum.Event.stopEvent);

  		if(this.main.options.map_type == "TYPE_SKYVIEW" && eObj.menu_type == "M_SKYVIEW"){
  			if( this.e_handler1 || this.e_handler2 ) return;
  			var mouseoverBinded = daum.Function.bindAsEventListener(this.mouseover, this);
			this.e_handler1 = daum.Event.addEvent(this.hybridp, 'mouseover', mouseoverBinded);	
			this.e_handler2 = daum.Event.addEvent(this.skyview, 'mouseover', mouseoverBinded);
  		}
 	},

	mouseover : function(event){
		this.hybrid_show();
	}, 

	mousemove : function(event){
	 	var element = event.srcElement || event.target;
		
		while(element.tagName != "BODY"){
			if( element.id == "hybridp" || element.id == "id_skyview" ){
				return false;
			}
			element = element.parentNode;
			if( !element) return false;
		}
		this.interval();
	},
 
	interval : function(){
		if( this.close_timer != null) return;
		this.close_timer = daum.Function.interval(this.hybrid_hide, 2000, this);
	}, 
	
	hybrid_show : function(){
		this.hybridp.style.display = 'block';
		if( this.e_handler3 ) return;
		//this.e_handler3 = daum.Event.addEvent(this.main.panel, 'mousemove', this.mousemove.bindAsEventListener(this));
		this.e_handler3 = daum.Event.addEvent(this.main.panel, 'mousemove', daum.Function.bindAsEventListener(this.mousemove, this));
	}, 
	
	hybrid_hide : function(){
		this.removeObserver("e_handler");
			 	
		this.hybridp.style.display = 'none';
		if(this.close_timer != null){
			window.clearInterval(this.close_timer);
			this.close_timer = null;
		}
	},
	
 	_remove_event : function(eObj){
  		this.removeObserver("defaultClickObserver");
 	},

	mapchanged_callback : function(nxt){
		if( !(this.listeners) || !(this.listeners["mapchanged"] )) return;
 
		var listenerLen = this.listeners["mapchanged"].length;
		for(var i=0; i<listenerLen; i++){
			//this.listeners["mapchanged"][i].bind(this)(nxt);
			this.listeners["mapchanged"][i].call(this, nxt);
	    }	
	}, 
	
	changed_callback : function(pre, nxt){
		if( !(this.listeners) || !(this.listeners["changed"] )) return;
		var listenerLen = this.listeners["changed"].length;
		for(var i=0; i<listenerLen; i++){
			//this.listeners["changed"][i].bind(this)(pre, nxt);
			this.listeners["changed"][i].call(this, pre, nxt);
	    }
	} 	 	
});
window.DMapTypeControl = daum.maps.DMapTypeControl;
/**
* DZoomControl - 라이프용 Zoom 컨트롤
*/
daum.maps.DZoomControl = function(options){
	this.$super();
	this.panel;

	this.plus; 
	this.minus;
	this.slide;
	this.mark; 
	this.scope;  	
	this.slideBox;
	this.map_type; 
	this.align = 'right';
	this.valign = 'top';
	
	this.level = 1; // 실제 level
	this.LEVEL_INTERVAL = 12; 
	this.MIN_LEVEL = 2; //0
	this.MAX_LEVEL = 15; 

	this.img_path = 'http://i1.daumcdn.net/localimg/life/images/detail/'; 
 	this.level_pos = new Array();

	this.sliding = false;
	this.clientY ;
	this.top ;  
	
	this.tools;
	this.main2; 
	this.indexMapControl = null;
 	 
	this.options = {
		hideIndexMapBtn : true, 
		diffIndexMap : false,
		diffIndexMap_callback : function(){}
	};	
	daum.extend(this.options, options || {});
	this.init();
};
daum.Function.inherit(daum.maps.DZoomControl, daum.maps.DControl);
daum.Function.members(daum.maps.DZoomControl, {
	name : "ZoomControl",

	init : function(){
	/* 
		for( var i=0; i< 15 ; i++){
			if( i <= 2){
				this.level_pos.push(0*this.LEVEL_INTERVAL-1);
			}else{
				this.level_pos.push(((i-2)*this.LEVEL_INTERVAL)-1);
			}
		}
 */		
		//this.addMapEvent("zoom", this.setZoomControl.bind(this));
		this.addMapEvent("zoom", daum.Function.bind(this.setZoomControl, this));		
		this.addInitFunction(this._setMapClient);		
		this._createControl();		
	}, 
	
	initControl : function(main){
		this.main = main;		
		
		if(this.initfunc.length > 0){			
			for(var i=0,len=this.initfunc.length; i<len; i++){
				this.initfunc[i].apply(this);				
			}			
		}
	},
	
	hideIndexMapBtn : function(){
		this.options.hideIndexMapBtn = false;
	}, 

	setPositionArray : function(){
		this.level_pos = [];
 		if(this.map_type == "TYPE_SKYVIEW" ){
			this.LEVEL_INTERVAL = 10; 
			this.MIN_LEVEL = 0;
 		}else{
			this.LEVEL_INTERVAL = 11; 
			this.MIN_LEVEL = 2;
 		}
 			
		for( var i=0; i< 15 ; i++){
			if( this.map_type == "TYPE_MAP" ){
				if( i <= 2){
					this.level_pos.push(9);
				}else{
					this.level_pos.push(((i-2)*this.LEVEL_INTERVAL)+9-1);
				}
			}else{
				this.level_pos.push((i*this.LEVEL_INTERVAL)+5-1);
			}
		}	
	}, 
	  
	_setMapClient : function(){
		this.main2 = this.main; 
		this.tools = this.main.tools;
		this.level = this.main.coordinate.getLevel();

		this.map_type = this.main.options.map_type;
		this.setPositionArray();
	//	this.slide.style.top = this.level_pos[this.level] + 'px';
		this.setLevel(this.level);
		this._bind_event();

		this._changeLevelStyle();
		
		for( var i=0; i< this.tools.controls.length; i++ ){
			if( this.tools.controls[i].name == "MapTypeControl"){
				//DEvent.addListener(this.tools.controls[i], 'mapchanged', this.setMapType.bind(this));
				DEvent.addListener(this.tools.controls[i], 'mapchanged', daum.Function.bind(this.setMapType, this));
			}
		}
 	},
		
	setMapType : function(nxt){
		this.map_type = nxt;
		this.setPositionArray();
		 
		//if( this.level != this.main.coordinate.getLevel() ){
			this.level = this.main.coordinate.getLevel();
	 		this.setLevel(this.level);		
			this._changeLevelStyle();
			this.mapZoomChange();
		//}
	},
	
	_bind_event : function(){		
		daum.Event.addEvent(this.main.panel, 'mouseup', daum.Function.bindAsEventListener(this.slide_mouseup, this));
 		daum.Event.addEvent(this.plus, 'click', daum.Function.bindAsEventListener(this.zoomin, this));
 		daum.Event.addEvent(this.plus, 'mousedown', daum.Function.bindAsEventListener(this.plus_mousedown, this.plus)); 
 		daum.Event.addEvent(this.plus, 'mouseover', daum.Function.bindAsEventListener(this.plus_mouseover, this.plus)); 
 		daum.Event.addEvent(this.plus, 'mouseout', daum.Function.bindAsEventListener(this.plus_mouseout, this.plus));
 		 
		daum.Event.addEvent(this.minus, 'click', daum.Function.bindAsEventListener(this.zoomout, this));
		daum.Event.addEvent(this.minus, 'mousedown', daum.Function.bindAsEventListener(this.minus_mousedown, this.minus));
		daum.Event.addEvent(this.minus, 'mouseover', daum.Function.bindAsEventListener(this.minus_mouseover, this.minus));
		daum.Event.addEvent(this.minus, 'mouseout', daum.Function.bindAsEventListener(this.minus_mouseout, this.minus));
				
		daum.Event.addEvent(this.mark, 'mousedown', daum.Function.bindAsEventListener(this.slide_mousedown, this));
		daum.Event.addEvent(this.mark, 'click', daum.stopEvent);
	 	daum.Event.addEvent(this.slideBg, 'click', daum.Function.bindAsEventListener(this.barclick, this));
	 	//daum.Event.addEvent(this.blueBg, 'click', this.barclick.bindAsEventListener(this));
	 	//daum.Event.addEvent(this.panel, 'click', this.barclick.bindAsEventListener(this));
 		daum.Event.addEvent(this.panel, 'mouseover', daum.Function.bindAsEventListener(this.panel_mouseover, this));
		daum.Event.addEvent(this.panel, 'mouseout', daum.Function.bindAsEventListener(this.panel_mouseout, this));
		
//		if( this.options.hideIndexMapBtn == true){
// 			if( this.options.diffIndexMap == true){
// 				daum.Event.addEvent(this.indexMapBtn, 'click', this.options.diffIndexMap_callback);
// 			}else{
// 				daum.Event.addEvent(this.indexMapBtn, 'click', daum.Function.bindAsEventListener(this.show_indexmap, this));
// 			}
// 		}	
	},
			
	getObject : function(){
 		return this.panel; 
	},
	
	show : function(){
		this.panel.style.display = "block";
	}, 
	
	hide : function(){
		this.panel.style.display = "none";
	}, 

	setAlign : function(align){
		this.align = align;
		if( this.main ){
			this.main.tools.changeAlign(this, this.panel);
		}	
	}, 
	
	setValign : function(valign){
		this.valign = valign;
		if( this.main ){
			this.main.tools.changeValign(this, this.panel);
		}	
	},
	
 	createElement : function(element){
 		var obj = document.createElement();
 		obj.style.padding = "0";
 		obj.style.margin = "0";
 		obj.style.fontSize = "0";
 	},
 	 
	_createControl : function(){
		try{
		 	var div_tmp = new daum.Template("<div style='font-size:0;margin:0;padding:0;#{style}' ></div>");
		 	var img_tmp = new daum.Template("<img src='#{src}' style='margin:0;padding:0;#{style}' width='22' height='15' />");
 
			this.panel = div_tmp.toElement({"style":"position:relative;width:22px;height:203px;z-index:402;"});
			this.panel.className = "ctrl_zoom";

 			this.plus = div_tmp.toElement({"style":"background:url("+ this.img_path +"bt_life_tm_control1.gif) no-repeat 0 0;height:20px;width:22px;cursor:pointer;position:relative;"})
 			this.panel.appendChild(this.plus);
 						
			this.slideBg = div_tmp.toElement({"style":"position:relative;margin-left:8px;z-index:1;;height:163px;width:6px;cursor:pointer;"});
			this.slideBg.setAttribute("id", 'slidebar');
			this.panel.appendChild(this.slideBg);

			this.blueBg = div_tmp.toElement({"style":"position:absolute;margin-left:8px;z-index:2;background:url("+ this.img_path +"ico_life_tm_control.gif) no-repeat -14px 0;height:163px;width:6px;cursor:pointer;top:0;left:-8px;"});
			this.blueBg.setAttribute("id", 'bluebar');
			this.slideBg.appendChild(this.blueBg);

			this.whiteBg = div_tmp.toElement({"style":"position:absolute;width:22px;height:221px;z-index:1;background:url("+ this.img_path +"ico_life_tm_control.gif) no-repeat 0 0;height:20px;width:6px;cursor:pointer;"});
			this.whiteBg.setAttribute("id", 'whiteBg');
			this.blueBg.appendChild(this.whiteBg);
						
			
 			this.mark = img_tmp.toElement({"src":this.img_path+"bt_life_tm_control2.png", "style":"position:absolute;z-index:3;cursor:pointer;top:0;left:-8px;"})
			this.slideBg.appendChild(this.mark);
 			
 			this.minus = div_tmp.toElement({"style":"background:url("+ this.img_path +"bt_life_tm_control1.gif) no-repeat -32px 0;height:20px;width:22px;cursor:pointer;position:relative;"})
 			this.panel.appendChild(this.minus);			

 			this.scope = div_tmp.toElement({"style":"position:absolute;width:27px;z-index:100;cursor:default;display:none;left:-20px;"});
			this.scopeBlock = this.scope.cloneNode(true);
			
//			if( this.options.hideIndexMapBtn == true){
//				this.indexMapBtn = div_tmp.toElement({"style":"position:absolute;top:0;left:-23px;background:url(http://i1.daumcdn.net/localimg/localimages/07/2008/map/new/n_local_control_btn.gif) no-repeat 0 0;height:20px;width:20px;cursor:pointer;"});
//				this.indexMapBtn.setAttribute("title", "미니맵 보이기");
//				this.panel.appendChild(this.indexMapBtn);
//			}	
			//var wingImg = img_tmp.toElement({"src":this.img_path + "n_local_blit_14.gif", "style":"margin:7px 0 0 3px;width:5px;height:9px;", "height":"9px", "width":"5px"});
			//this.leftWing.appendChild(wingImg);
			
						
			if( this.map_type ){
			 	this._changeLevelStyle();
			}
			this.panel.appendChild(this.scope);
			this.panel.appendChild(this.scopeBlock); 			
			
			this.panel.eventDMapControls = true;
		}catch(e){
			console.debug(e.message);
		}		
	},
	 	 
	_changeLevelStyle : function(){
 		if(this.map_type == "TYPE_SKYVIEW" ){
 			//this.blueBg.style.background =  "url("+this.img_path+"n_local_control_2d_1.gif) no-repeat -44px 0";
 			//this.whiteBg.style.background = "url("+this.img_path+"n_local_control_2d_1.gif) no-repeat -30px 0";
 			this.blueBg.style.backgroundPosition =  "-44px 0";
 			this.whiteBg.style.backgroundPosition = "-30px 0";
			this.scope.style.height = "163px";
			this.scope.style.top = "20px"; 			
 		}else{
 			//this.blueBg.style.background =  "url("+this.img_path+"n_local_control_2d_1.gif) no-repeat -14px 0";
 			//this.whiteBg.style.background = "url("+this.img_path+"n_local_control_2d_1.gif) no-repeat 0 0";
 			this.blueBg.style.backgroundPosition =  "-14px 0";
 			this.whiteBg.style.backgroundPosition = "0 0";
			this.scope.style.height = "163px";
			this.scope.style.top = "20px"; 			
 		}
		this.scopeBlock.setAttribute("id", 'scopeblock');
		this.scopeBlock.style.zIndex = "101";
		this.scopeBlock.style.top = this.scope.style.top;
		this.scopeBlock.style.height = this.scope.style.height;  
		
		this._setBlockScope();

//		if(this.map_type == "TYPE_SKYVIEW" ){
//			daum.Element.setPngOpacity(this.scope, this.img_path+"n_local_control_txt02_1.png");
//		}else{
//			daum.Element.setPngOpacity(this.scope, this.img_path+"n_local_control_txt01_1.png");
//		}
	},
	
	_setBlockScope : function(){
		try{
			this.scopeBlock.innerHTML = "";
		 	var div_tmp = new daum.Template("<div style='position:absolute;font-size:0;margin:0;padding:0;width:27px;height:11px;cursor:pointer;#{style}' ></div>");
		 	var spot = [];
		 	var top = [];
		 	if(this.map_type == "TYPE_SKYVIEW" ){
		 		spot = [2, 5, 9, 11, 13]; 
		 		top = [27, 55, 95, 115, 134];
		 	}else{
		 		spot = [2, 5, 9, 11, 13];
		 		top = [9, 42, 86, 108, 130];
		 	}
		 	
		 	var box1 = div_tmp.toElement({"style" : "top:" + top[0] + "px;"});
		 	var box2 = div_tmp.toElement({"style" : "top:" + top[1] + "px;"});
		 	var box3 = div_tmp.toElement({"style" : "top:" + top[2] + "px;"});
		 	var box4 = div_tmp.toElement({"style" : "top:" + top[3] + "px;"});
		 	var box5 = div_tmp.toElement({"style" : "top:" + top[4] + "px;"});
		 	
			box1.level = spot[0]; 	 	
			box2.level = spot[1];
			box3.level = spot[2];
			box4.level = spot[3];
			box5.level = spot[4];
			
			this.scopeclickBinded = daum.Function.bindAsEventListener(this.scopeclick, this);
		 	daum.Event.addEvent(box1, 'mousedown', this.scopeclickBinded);
		 	daum.Event.addEvent(box2, 'mousedown', this.scopeclickBinded);
		 	daum.Event.addEvent(box3, 'mousedown', this.scopeclickBinded);
		 	daum.Event.addEvent(box4, 'mousedown', this.scopeclickBinded);
		 	daum.Event.addEvent(box5, 'mousedown', this.scopeclickBinded);
		 	
		 	this.scopeBlock.appendChild( box1 );
		 	this.scopeBlock.appendChild( box2 );
		 	this.scopeBlock.appendChild( box3 );
		 	this.scopeBlock.appendChild( box4 );
		 	this.scopeBlock.appendChild( box5 );
	 	}finally{
			div_tmp = null;
			spot = null;
			top = null; 
	 	}
	}, 
	
	mapZoomChange : function() {
		//this.main.zoomTo(this.main.coordinate.SCALE_LIST[this.level]);
		this.main.coordinate.setCoord(this.main.coordinate.centerPoint,this.main.coordinate.SCALE_LIST[this.level], this.main.options.coordinateType);
		this.main.requestMap(1);
 	},	
		
	setZoomControl : function(val, val2){
		if( val != this.level){
			this.setLevel(val);	
		}
	}, 
	
	setLevel : function(level){
		this.level = level;
		this.mark.style.top = this.level_pos[this.level] + 'px';
		this.whiteBg.style.height = (this.level_pos[this.level] + 8) + 'px';
	},
	
	zoomin : function(event){
		this.plus.style.backgroundPosition = "0 -25px";
		
		if( this.main.options.map_type == "TYPE_MAP" ){
			this.MIN_LEVEL = 2;
		}else if( this.main.options.map_type == "TYPE_SKYVIEW" ){
			this.MIN_LEVEL = 0;
		}
	
		if( this.level == this.MIN_LEVEL  ){
			return; 
		}
		if( this.level > this.MIN_LEVEL ){
			this.level --;
		}
		this._setZoom(); 
	},
	
	zoomout : function(event){
		this.minus.style.backgroundPosition = "-32px -25px";
		
		if( this.level == this.MAX_LEVEL-1 ){
			return; 
		}
		if( this.level < this.MAX_LEVEL ){
			this.level ++; 
		}
		this._setZoom(); 
	},
	
	barclick : function(event){
		try{	
			var offsetY; 
 			if( event.layerY ){
 				offsetY = event.layerY; 
			}else{
				offsetY = event.offsetY; 
			}
			this.level = Math.floor(offsetY/this.LEVEL_INTERVAL);
			
			if( this.main2.options.map_type == "TYPE_MAP"){
				this.level = Math.min(this.level, 12);
				this.level +=2; 
			}else{
				this.level = Math.min(this.level, 14);
			}
 			this._setZoom(); 
 			//daum.Event.stopEvent(event);
		}catch(e){
			console.debug(e.message);
		}			 		
	},
	
	scopeclick : function(event){
		try{
			var element = event.srcElement || event.target;
			this.level = element.level;
 			this._setZoom(); 
		}catch(e){
			console.debug(e.message);
		}			 		
	},	
	
 	_setZoom : function(){
		this.mark.style.top = this.level_pos[this.level] + 'px';
		this.whiteBg.style.height = (this.level_pos[this.level] + 8) + 'px';
		
 		if( this.sliding != true){
 			this.mapZoomChange();
 		}	
	},
	
	show_indexmap : function(){
		if( this.indexMapControl == null ){
		 	this.indexMapControl = new DIndexMapControl(this);
		 	this.tools.addTools(this.indexMapControl);
		}
		if(this.indexMapControl.panel.style.display != 'none' ){
			this.indexMapControl.panel.style.display = 'none';
			this.indexMapBtn.style.display = "block";
		}else{
			this.indexMapControl.panel.style.display = 'block';
			this.indexMapBtn.style.display = "none";
		}
	},

		
	slide_mousedown : function(event){
		try{
		if( this.sliding != true){
			this.sliding = true;
			this.clientY = event.clientY;
			this.top = parseInt(this.mark.style.top);

			//daum.Event.addEvent(this.main.panel, 'mousemove', this.slide_mousemove.bindAsEventListener(this));
			daum.Event.addEvent(this.main.panel, 'mousemove', daum.Function.bindAsEventListener(this.slide_mousemove, this));
		 	daum.preventDefault(event);
			return false;
		}
		}catch(e){
			console.debug(e.message);
		}
	}, 
	
	slide_mousemove : function(event){
		try{
			if( this.sliding == true){
				var pos = this.top + event.clientY - this.clientY;
	 
			 	if( this.level_pos[this.MIN_LEVEL] > pos || this.level_pos[this.MAX_LEVEL-1] < pos){
			 		return false;
			 	}
	 			this.mark.style.top = pos + 'px';
	 			this.whiteBg.style.height = (pos + 8) + 'px';
	 			
	 			for(var i=0 ; i<this.MAX_LEVEL; i++){
	 				if( i==14 && this.level_pos[i] <= pos){
						this.level = this.MAX_LEVEL-1;
						break;
					}else if( this.level_pos[i]<=pos && this.level_pos[i+1]>pos){
						this.level = i; 
						break;
					}
				}
			}
		}catch(e){
			console.debug(e.message);
		}
		return false;
		
	},
			
	slide_mouseup : function(event){
		if(this.sliding != false){
			this.mark.style.top = this.level_pos[this.level] + 'px';
			this.whiteBg.style.height = (this.level_pos[this.level] + 8) + 'px';
			this.sliding = false;
			this.mapZoomChange();
		}
		return false;
	},
 
	panel_mouseover : function(event){
		this.scope.style.display = "block";
		this.scopeBlock.style.display = "block";
	},
	
	panel_mouseout : function (event){
		this.scope.style.display = "none";
		this.scopeBlock.style.display = "none";
	}, 
	
	plus_mouseover : function(event){
		this.style.backgroundPosition = "0 -25px";
	}, 
	
	plus_mouseout : function(event){
		this.style.backgroundPosition = "0 0px";
	}, 
 
	plus_mousedown : function(event){
		this.style.backgroundPosition = "0 -50px";
	}, 

	minus_mouseover : function(event){
		this.style.backgroundPosition = "-32px -25px";
	}, 
	
	minus_mouseout : function(event){
		this.style.backgroundPosition = "-32px 0px";
	}, 
 
	minus_mousedown : function(event){
		this.style.backgroundPosition = "-32px -50px";
	} 	
});
window.DZoomControl = daum.maps.DZoomControl;
