/** 팝업 변수 저장 객체 */
var popupArray = new Array();
/** 타이머 5분 */
var timerFive = 300000;
/** 타이머 1분 */
var timerOne = 60000;
/** obe타이머 객체 */
var obeTimer = null;
/** 돌발타이머 객체 */
var imsTimer = null;
/** FOOTER 전면통제 타이머 객체 */
var footTimer = null;
/** 소통정보 타이머 객체 */
var trafficTimer = null;
/** 브라우저 종류 */
var UserAgent = window.navigator.userAgent;
/** 지역선택 토글 */
var regSelect = false;

$(document).ready(function () {
	// 외부망이면서 ie 접근인경우 mac확인 페이지로 리턴 
	if(successYn !== 'success' && checkMac === 'true' && IPFLAG!== 'true'){
		if(detectIE()){
			location.href = CONTEXTROOT + '/checkMacAddress.do';					
		} else {
			location.href = CONTEXTROOT + '/checkConnection.do?key=' + KEY;
		}
	}
	
	// 맥어드레스 체크 확인되면 다시 쿠키 초기화
	setCookie('macChk','',1);
	document.oncontextmenu = new Function('return false');  

	if(window.location.protocol.indexOf('https') !== -1){
		connectUrl = getHttpsUrl(connectUrl);
	} else {
		location.protocol = 'https:';
	}

	function getHttpsUrl(url){
		if('undefined' === typeof(url) || null == url || '' === url || url.indexOf('http') === -1){
			return '';
		}
		
		return 'https' + url.substring(url.indexOf(':'));
	}

	init();
	getWeatherInfo();
	
	//전면통제
	getFooter();
	
	//지역 SELECTBOX
	getSelectCity();
	
	//소통정보표출
	mapTraffic();
	
	//소통정보 기준시간 표출
	changeTimeDisplay();
	
	// 소통정보 박스 위치 조정
	relocateTrafficInfoBox();

	/* 2022.12.12 mgkim 지역선택 재개발에 따른 기존기능 백업
	$('#input2').change(getSelectRoad);
	*/
	
	document.getElementById("keyword")
    	.addEventListener("keyup", function(event) {
	    
	    let eventKey = event.key;
	    let cmpValue = 'Enter';
	    
	    event.preventDefault();
	    
	    if('undefined' === typeof(eventKey)){
			eventKey = event.keyCode;
			cmpValue = 13;
		}
	    
	    if (eventKey === cmpValue) {
	        document.getElementById("searchBtn").click();
	    }
	});
	
	$('#btnStreetView').click(function(){
		if($('#btnStreetView').attr('class').indexOf('ico_sky_on') !== -1){
			return;
		}
		
		switchViewControl('street');
		map.setMapTypeId(kakao.maps.MapTypeId.ROADMAP);
	});
	
	$('#btnSateliteView').click(function(){
		if($('#btnSateliteView').attr('class').indexOf('ico_earth_on') !== -1){
			return;
		}
		
		switchViewControl('satelite');
		map.setMapTypeId(kakao.maps.MapTypeId.HYBRID);
	});
	
	/**************************************************************
	 * 반응형 웹 
	 **************************************************************/
	checkDisplayType()

	/********************************************************************************
	 * 메뉴버튼
	 * traffic : 소통정보
	 * ims : 돌발
	 * cctv : CCTV
	 * place : 위치검색
	 * cctcMng : 고속도로/국도cctv
	*********************************************************************************/
	$(".toggleBtn > a").click(function(e) {

		var obj = $(this).attr("class");
		var iconBtn = $("#" + obj).attr("class");

		$('#' + obj).toggleClass('road_on road_off');

		if (obj == "traffic") {
			$("#traffic").toggleClass('btn01_on btn01');
			$(".info_wrap").toggleClass('on');
		}

		if (obj == "ims") {
			$("#ims").toggleClass('btn02_on btn02');
		}

		//시내CCTV
		if (obj == "cctv") {
			if (iconBtn == "road_on") {
				$("#cctv").attr("src", BTN_IMAGE_PATH + "btn03.gif");
				$("#cctv_m").removeClass('on');
			} else {
				$("#cctv").attr("src", BTN_IMAGE_PATH + "btn03on.gif");
				$("#cctv_m").addClass('on');
			}
		}
		
		//고속도로
		if (obj == "roadCctv") {
			if (iconBtn == "road_on") {
				$("#roadCctv").attr("src", BTN_IMAGE_PATH + "btn05.gif");
				$("#roadCctv_m").removeClass('on');
			} else {
				$("#roadCctv").attr("src", BTN_IMAGE_PATH + "btn05on.gif");
				$("#roadCctv_m").addClass('on');
			}
		}

		//국도CCTV
		if (obj == "roadCctvE05") {
			if (iconBtn == "road_on") {
				$("#roadCctvE05").attr("src", BTN_IMAGE_PATH + "btn07.gif");
				$("#roadCctvE05_m").removeClass('on');
			} else {
				$("#roadCctvE05").attr("src", BTN_IMAGE_PATH + "btn07on.gif");
				$("#roadCctvE05_m").addClass('on');
			}
		}

		//시내CCTV
		if (obj.indexOf("cctv_m") !== -1) {
			if ($('#cctv').attr('class').indexOf("road_on") !== -1) {
				$("#cctv").attr("src", BTN_IMAGE_PATH + "btn03.gif");
				$("#cctv_m").removeClass('on');
			} else {
				$("#cctv").attr("src", BTN_IMAGE_PATH + "btn03on.gif");
				$("#cctv_m").addClass('on');
			}
		}
		
		//고속도로
		if (obj.indexOf("roadCctv_m") !== -1) {
			if ($('#roadCctv').attr('class').indexOf("road_on") !== -1) {
				$("#roadCctv").attr("src", BTN_IMAGE_PATH + "btn05.gif");
				$("#roadCctv_m").removeClass('on');
			} else {
				$("#roadCctv").attr("src", BTN_IMAGE_PATH + "btn05on.gif");
				$("#roadCctv_m").addClass('on');
			}
		}

		//국도CCTV
		if (obj.indexOf("roadCctvE05_m") !== -1) {
			if ($('#roadCctvE05').attr('class').indexOf("road_on") !== -1) {
				$("#roadCctvE05").attr("src", BTN_IMAGE_PATH + "btn07.gif");
				$("#roadCctvE05_m").removeClass('on');
			} else {
				$("#roadCctvE05").attr("src", BTN_IMAGE_PATH + "btn07on.gif");
				$("#roadCctvE05_m").addClass('on');
			}
		}
	
		if (obj == "place") {
			if (iconBtn == "road_on") {
				$("#place").attr("src", BTN_IMAGE_PATH + "search.png");
			} else {
				$("#place").attr("src", BTN_IMAGE_PATH + "searchOn.png");
			}
		}

		if (obj == "intSig") {
			$("#intSig").toggleClass('btn08_on btn08');
		}

		//기상정보
		if (obj == "weather") {
			$("#weather").toggleClass('btn09_on btn09');
		}

		//로드뷰
		if (obj == "road") {
			if (iconBtn == "road_on") {
				$("#road").attr("src", BTN_IMAGE_PATH + "road_view.gif");
			} else {
				$("#road").attr("src", BTN_IMAGE_PATH + "road_viewon.gif");
				$("#area").attr("src", BTN_IMAGE_PATH + "area.png");
				$("#area").removeClass("road_on").addClass("road_off");
				$("#draw").attr("src", BTN_IMAGE_PATH + "distance.png");
				$("#draw").removeClass("road_on").addClass("road_off");
			}
		}

		//거리재기
		if (obj == "draw") {
			if (iconBtn == "road_on") {
				$("#draw").attr("src", BTN_IMAGE_PATH + "distance.png");
			} else {
				$("#draw").attr("src", BTN_IMAGE_PATH + "distanceon.png");
				$("#area").attr("src", BTN_IMAGE_PATH + "area.png");
				$("#area").removeClass("road_on").addClass("road_off");
				$("#road").attr("src", BTN_IMAGE_PATH + "road_view.gif");
				$("#road").removeClass("road_on").addClass("road_off");
			}
		}

		//면적재기
		if (obj == "area") {
			if (iconBtn == "road_on") {
				$("#area").attr("src", BTN_IMAGE_PATH + "area.png");
			} else {
				$("#area").attr("src", BTN_IMAGE_PATH + "areaon.png");
				$("#draw").attr("src", BTN_IMAGE_PATH + "distance.png");
				$("#draw").removeClass("road_on").addClass("road_off");
				$("#road").attr("src", BTN_IMAGE_PATH + "road_view.gif");
				$("#road").removeClass("road_on").addClass("road_off");
			}
		}

		if (obj == "obdId") {
			if (iconBtn == "road_on") {
				$("#obdId").attr("src", BTN_IMAGE_PATH + "btn_obd.gif");
			} else {
				$("#obdId").attr("src", BTN_IMAGE_PATH + "btn_obdon.gif");
			}
		}
		
		if (obj == "selectRegion") {
			if(regSelect){
				regSelect = false;
			} else{
				$("#selectRegion").toggleClass('btn010 btn010_on');
			}
		}
	});

	$('#cctvList').click(function(e) {
		if (e.target === $('#cctvList')[0]) { // cctvList show/hide 버튼
			let iconBtn = $('#cctvList').attr('class');

			$("#cctvList").toggleClass('road_on road_off');
			
			if($('#cctvList').attr('class').indexOf("road_on") !== -1){
				$("#cctvList").addClass('btn_cctv_on');	
				$("#cctvList").removeClass('btn_cctv');	
			} else {
				if($('#cctv').attr('class').indexOf('road_on') !== -1 || 
					$('#roadCctv').attr('class').indexOf('road_on') !== -1 || 
					$('#roadCctvE05').attr('class').indexOf('road_on') !== -1){
						$("#cctvList").addClass('btn_cctv_on');	
						$("#cctvList").removeClass('btn_cctv');
					} else {
						$("#cctvList").addClass('btn_cctv');	
						$("#cctvList").removeClass('btn_cctv_on');
					}
			}
			

			if (displayType == DISPLAY_PC) {
				if (iconBtn.indexOf("road_on") !== -1) {
					$('.slide').animate({
						'left': -430
					}, 200, function() {
						$('.header > .i_p00 > li:nth-child(6)').css('left', '-431px');
						$('.header > .i_p00 > li:nth-child(7)').css('left', '-431px');
					});
				} else {
					$('.slide').animate({
						'left': 0
					}, 200, function(){
						$('.header > .i_p00 > li:nth-child(6)').css('left', '-1px');
						$('.header > .i_p00 > li:nth-child(7)').css('left', '-1px');
					});
				}
			} else {
				let isOn = $('#cctvList').attr('class').indexOf("road_on") !== -1;

				if (isOn) {
					$('.submenu_wrap').show();
				} else {
					$('.submenu_wrap').hide();
				}
			}
		}
	});

	/********************************************************************************
	 * OFF CCTV클릭
	*********************************************************************************/
	$(".toggleBtn2 > a").click(function() {
		var obj = $(this).attr("class");

		if (obj == "cctvOff" && $('#cctvList').attr('class').indexOf('road_on') !== -1) {
			$("#cctvOff").attr("src", BTN_IMAGE_PATH + "btn06on.gif");
		}
	});

	$(".toggleBtn2 > a").mouseout(function() {
		var obj = $(this).attr("class");

		if (obj == "cctvOff") {
			$("#cctvOff").attr("src", BTN_IMAGE_PATH + "btn06.gif");
		}
	});

	/********************************************************************************
	 * header display
	*********************************************************************************/
	$("#hline").click(function() {
		$(".header").slideToggle("slow");
	});

	/********************************************************************************
	 * OBEID버튼 display
	*********************************************************************************/
	$("#obdBtn").click(function() {
		var obj = $(this).attr("class");

		if (obj == "obd2") {
			$(".obd2").removeClass('obd2').addClass("obd3");
			$(".obd").css("display", "block");
		} else {
			$(".obd3").removeClass("obd3").addClass("obd2");
			$(".obd").css("display", "none");
		}
	});

	/********************************************************************************
	 * 상단 메뉴 드래그 스크롤
	*********************************************************************************/
	draggable($('.i_p00')[0]);

	/********************************************************************************
	 * 맵 컨트롤(반응형 웹)
	*********************************************************************************/
	$(window).resize(checkDisplayType);

	/********************************************************************************
	 * 소통정보범례
	*********************************************************************************/
	$('#trafficInfoClose').click(function() {
		$('.info_wrap').hide();
	});
	
	$('#trafficInfoBoxClose').click(trafficInfoBoxClose);
	
	/********************************************************************************
	 * 지역선택버튼
	*********************************************************************************/
	/*
	$('#input2').focusout(function(){
		removeSelectRegionFocus()
	});
	
	$('#input2').keydown(function(e){
		if(e.keyCode === 27){
			removeSelectRegionFocus()
		}
	});
	
	document.getElementById('input2').addEventListener('backbutton', function(){
		removeSelectRegionFocus()
	});
	
	$('#map').click(removeSelectRegionFocus);
	*/
	$('#map').click(function(e) {
    if(e && e.target.getAttribute('id') === 'fade'){
      closeSelectRegion();
    }
  }); // 2022.12.16 mgkim 지도 클릭시 지역선택 팝업 닫기
	
	/**
	 * 페이지 로드 시 sessionList 불러오기
	 */
	
	var varUA = navigator.userAgent.toLowerCase(); //userAgent 값 얻기
 
    if ( !detectIOS() && !detectSafari() ) {
        showLoaderAll(true);
        
		let isSecure = window.location.protocol.indexOf('https') !== -1;
		
		amsServer = new AcesServerAMS7000(serverIp, serverPort, true, true);
		setServerDefaultSettings(amsServer);
		amsServer.setTitle('MainServer');
		amsServer.getSessionList((list) => {
			if('undefined' === typeof(list)){
				alert('list is undefined');	
			} else {
				sessionList = list;
			}
			
			showLoaderAll(false);
		});
    }
});

function removeSelectRegionFocus(){
	$('#selectRegion').addClass('btn010 road_off');
	$('#selectRegion').removeClass('btn010_on road_on');
}

// css 로드
function appendCss(){
	let head = document.getElementsByTagName( "head" )[0]; 
	let cssFiles = [
		'main.css',
		'weather.css',
		'tablet.css',
		'jquery/jquery.li-scroller.css',
	]
	
	for(let i = 0; i < cssFiles.length; i++){
		head.appendChild(createCssElement(cssFiles[i]));	
	}
}

function createCssElement(fileName){
	var link = document.createElement( "link" );
	
	link.href = CONTEXTROOT + '/css/' + fileName;
	link.type = "text/css";
	link.rel = "stylesheet";
	link.media = "screen,print";
	
	return link;
}

/********************************************************************************
 footer 돌발전면통제
*********************************************************************************/
var footerId;
function getFooter() {
	
	if(footerId != null) clearTimeout(footerId);
	var option = {
			url		 : "main/getFooter.do",
			param	 : {},
			callback : getFooterCallback
		};
	
		callService(option);
		footerId = setTimeout('getFooter()',timerOne);
}
var troublePoint = new Array();
var troubleImg 	 = new Array();
var troubleTitle = new Array();
function getFooterCallback(json) {
	
	var list = json.data.list;
	var iRow = list.length;
	
	var strUI = "";
	var str  = "";
	
	var lon = "";
	var lat = "";
  
	if(iRow > 0) {
		
		getFooterBtn('A');
		
		$("#footerDiv").html("");
		
		strUI ="<ul id=\"ticker01\"></ul>";
		
		for(var i = 0; i < iRow; i ++) {
			
			lon = list[i].LOCATION_DATA_X;
			lat = list[i].LOCATION_DATA_Y;
			
			//결과값 배열
			troublePoint[i] = [list[i].LOCATION_DATA_Y, list[i].LOCATION_DATA_X, list[i].INCIDENT_ID,
				             list[i].INCIDENT_TYPE_CD, list[i].INCIDENT_TITLE, list[i].INCIDENT_REPORT,
				             list[i].START_DATE, list[i].END_DATE];
			
			troubleImg[i] 	= "btn_trouble_A.gif";
			troubleTitle[i] = "전면통제";
			
			if(i < 1) {
				
				str += "<li><a href=\"javascript:setTroubleMarker('" + i + "','" + lat + "','" + lon + "');\">" + list[i].FOOTER_TITLE + "&nbsp;&nbsp;</a></li>";
			}else {
				
				str += "<li><a href=\"javascript:setTroubleMarker('" + i + "','" + lat + "','" + lon + "');\">  / " + list[i].FOOTER_TITLE + "&nbsp;&nbsp;</a></li>";
			}
		}
		
		$("#footerDiv").html(strUI);
		
		$("#ticker01").html(str);
		
		//푸터 롤링
		getScroll();
		
	}else {
		
		getFooterBtn('B');
	}
}
/********************************************************************************
 * 푸터 롤링
*********************************************************************************/
function getScroll() {
	
	 $(function(){
		$("#ticker01").liScroll({travelocity: 0.1});
	 });
}
/********************************************************************************
 * 전면통제마커표출
*********************************************************************************/
function setTroubleMarker(k, lat, lon) {
	
	var points = new Array();
	var img    = new Array();
	var title  = new Array();
	
	points[0] = troublePoint[k];
	img[0] 	  = troubleImg[k];
	title[0]  = troubleTitle[k];
	
	var iconBtn = $("#ims").attr("class");
	
	//전면통제 마커 초기화
	markerRemove("trouble");
	
	if (iconBtn.indexOf("road_off") !== -1) {
		
		setBounds(lat, lon, 4);
		
		setMarker(points, title, "trouble", img, 50);  
	
	}else {
		
		setBounds(lat, lon, 4);
	}
}
/********************************************************************************
 * 도시 SELECTBOX 리스트조회
*********************************************************************************/
function getSelectCity() {
	
	var selectSido = nvl($("#input1 option:selected").val(), ""); 
	
	var option = {
			url		 : "main/getSelectCity.do",
			param	 : {SIDO_CODE:selectSido},
			callback : getSelectCityCallback
		};
	
		callService(option);
}
/* 2022.12.12 mgkim 지역선택 재개발에 따른 기존기능 백업
function getSelectCityCallback_bk221213(json) {
	
	var list = json.data.list;
	var iRow = list.length;
	var str  = "<option value=''>--지역 선택--</option>"; //조병조 작업구간 텍스트변경
	var preSidoCode = '';
	var sidoCode = '';
	if(iRow > 0) {
		
		for(var i = 0; i < iRow; i ++) {
			
			sidoCode = list[i].SIDO_CODE;
			
			if(preSidoCode!='' &&preSidoCode != sidoCode){

				str += "<optgroup label='"+getSidoGrpName(sidoCode)+"'>";
			}
			
			str += "<option value='"+ list[i].CENTERID + "@" + list[i].XCOORD + "@" +list[i].YCOORD + "@" + list[i].VIEW_LEVEL +"'>" + list[i].CENTERNAME + "</option>";
			
			preSidoCode = sidoCode;
		}
	}
	
	$("#input2").html(str);
}*/
// 2022.12.16 mgkim 지역선택 폼 세팅 구현
function getSelectCityCallback(json) {
	var list = json.data.list;
	var iRow = list.length;
	var str  = ""; 
	var preSidoCode = '';
	var sidoCode = '';
	if(iRow > 0) {
		for(var i = 0; i < iRow; i ++) {
			sidoCode = list[i].SIDO_CODE;
			if(sidoCode=='00'){// 전국
				str += "<ul class='ulSelRegionOne'><div><li onclick=\"moveCity('"+ list[i].CENTERID + "@" + list[i].XCOORD + "@" +list[i].YCOORD + "@" + list[i].VIEW_LEVEL +"')\" value='"+ list[i].CENTERID + "@" + list[i].XCOORD + "@" +list[i].YCOORD + "@" + list[i].VIEW_LEVEL +"'>" + list[i].CENTERNAME + "</li>";
			}else if(i==iRow-1){// 마지막
				if(preSidoCode!='' &&preSidoCode != sidoCode){
					str += "</div></ul><ul><li class='ul_h'>"+getSidoGrpName(sidoCode)+"</li><div class='divRegionScroll'>";
				}
				str += "<li onclick=\"moveCity('"+ list[i].CENTERID + "@" + list[i].XCOORD + "@" +list[i].YCOORD + "@" + list[i].VIEW_LEVEL +"')\" value='"+ list[i].CENTERID + "@" + list[i].XCOORD + "@" +list[i].YCOORD + "@" + list[i].VIEW_LEVEL +"'>" + list[i].CENTERNAME + "</li></div></ul>";
			}else{
				if(preSidoCode!='' &&preSidoCode != sidoCode){
					str += "</div></ul><ul><li class='ul_h'>"+getSidoGrpName(sidoCode)+"</li><div class='divRegionScroll'>";
				}
				str += "<li onclick=\"moveCity('"+ list[i].CENTERID + "@" + list[i].XCOORD + "@" +list[i].YCOORD + "@" + list[i].VIEW_LEVEL +"')\" value='"+ list[i].CENTERID + "@" + list[i].XCOORD + "@" +list[i].YCOORD + "@" + list[i].VIEW_LEVEL +"'>" + list[i].CENTERNAME + "</li>";
			}
			preSidoCode = sidoCode;
		}
	}
	$("#ulSelRegion").html(str);
	
	// 2023.02.28 mgkim 지역선택 그룹별 toggle기능 추가
	var regionGroup = $('li.ul_h');
	var regionDetail = $('div.divRegionScroll');
	regionDetail.hide();
	regionGroup.click(function(){
		$(this).nextUntil('li.ul_h').toggle();
	})
}

// 2022.12.12 mgkim 지역선택 폼 호출
function showSelectRegion() {
    //Fade in Background
    //$('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
    $("#fade").fadeIn(); 
    $("#fade").fadeTo("slow", 0.5);
    
    $(".divSelRegion").animate({scrollTop:0}, 100);//2022.12.16 mgkim 호출시마다 스크롤 최상단 고정
    $(".divRegionScroll").animate({scrollTop:0}, 100);//2022.12.20 mgkim 호출시마다 스크롤 최상단 고정
    
    $("#selectRegionPopup").show();
    
    $('#selectRegion').addClass('btn010_on');
	$('#selectRegion').removeClass('btn010');

}

/********************************************************************************
 * 지역선택 Div 닫기
*********************************************************************************/
function closeSelectRegion() {
    //When clicking on the close or fade layer...
    $("#fade , .selectRegion_popup_block").fadeOut(function () {}); //fade them both out
    
    $('#selectRegion').addClass('btn010');
    $('#selectRegion').removeClass('btn010_on');
}

/********************************************************************************
 * ROAD SELECTBOX 리스트조회
*********************************************************************************/
/* 2022.12.12 mgkim 지역선택 재개발에 따른 기존기능 백업
function getSelectRoad() {
	
	var selectCity = nvl($("#input2 option:selected").val(), ""); 
	
	$('#selectRegion').addClass('road_off btn010');
	$('#selectRegion').removeClass('road_on btn010_on');
	
	regSelect = true;
	
	if(selectCity != "") {
		
		var CENTERID = selectCity.split("@");
		
		var option = {
				url		 : "main/getSelectRoad.do",
				param	 : {CENTERID : CENTERID[0]},
				callback : getSelectRoadCallback
			};
			callService(option);
	
	}else {
		
		$("#input3").html("<option value=''>--선택--</option>");
	}
}
function getSelectRoadCallback(json) {
	
	var list = json.data.list;
	var iRow = list.length;
	var str  = "<option value=''>--선택--</option>";
	
	if(iRow > 0) {
		
		for(var i = 0; i < iRow; i ++) {
			
			str += "<option value='"+ list[i].ROADID + "@" + list[i].XCOORD + "@" + list[i].YCOORD + "@" + list[i].VIEW_LEVEL + "@" + list[i].CCTVID +"'>";
			str += list[i].ROADNAME;
			str += "</option>";
		}
	}
	
	$("#input3").html(str);
	
	moveCity();
}
*/
/********************************************************************************
 * 도시이동
*********************************************************************************/
/* 2022.12.12 mgkim 지역선택 재개발에 따른 기존기능 백업
function moveCity() {
	
	var selectCity = nvl($("#input2 option:selected").val(), "");
	
	if(selectCity != "") {
		
		var xy = selectCity.split("@");
		
		setBounds(xy[2],xy[1], xy[3]);
	
	}else {
		
		alert("이동하실 지역을 선택하여 주십시오.")
	}
}
*/
/* 2022.12.15 mgkim 지역이동 파라메타 받아서 이동하게 수정 */
function moveCity(selCtiy) {
	var selectCity = nvl(selCtiy, "");
	if(selectCity != "") {
		var xy = selectCity.split("@");
		setBounds(xy[2],xy[1], xy[3]);
	}else {
		alert("이동하실 지역을 선택하여 주십시오.")
	}
	closeSelectRegion();
	
}

/********************************************************************************
 * road 이동
*********************************************************************************/
function moveRoad() {
	
	var selectRoad = nvl($("#input3 option:selected").val(), "");
	
	if(selectRoad != "") {
		
		var xy = selectRoad.split("@");
		var cctvOnOff = $("#cctv").attr("class");
		
		setBounds(xy[2],xy[1], xy[3]);
		
		if(cctvOnOff.indexOf("road_off") !== -1) {
			//getCCTV(xy[4]);
		}else {
			//$("#cctvRoad").val(xy[4]);
		}
		
	}else {
		
		alert("이동하실 위치를 선택하여 주십시오.")
	}
}

/********************************************************************************
 * 시내도로 CCTV조회
*********************************************************************************/
var cctvAjaxReq=null;
function getCCTV(CCTVID) {
	
	if(cctvAjaxReq!=null){
		if(cctvAjaxReq.readyState == 1){
			cctvAjaxReq.abort();
			cctvAjaxReq = null;
		}
	}
	var flag = $("#cctv").attr("class");
	var cctvId = nvl(CCTVID, "");
	var level = map.getLevel();
	
	if(level < CCTV_VIEW_LEVEL) {
		
		if((flag.indexOf("road_on") !== -1) || (cctvId != "")) {
			var option = {
					url		 : "main/getCCTV.do",
					param	 : {  MIN_X : $("#min_x").val()
								, MIN_Y : $("#min_y").val()
								, MAX_X : $("#max_x").val()
								, MAX_Y : $("#max_y").val()
								, IPFLAG : IPFLAG
								, CCTVID : cctvId
								},
					callback : getCCTVCallback
				};
			cctvAjaxReq = callService(option);
		} else {
			markerRemove("cctv");
			cctvClose();
		}
	}
}
function getCCTVCallback(json) {
		
	var list = json.data.cctvList;
	var iRow = list.length;
	
	var title 	= new Array();
	var lon 	= new Array();
	var lat 	= new Array();
	var id 		= new Array();
	var points 	= new Array();
	var img		= new Array();
	
	level = map.getLevel();
	
	if(iRow > 0) {
		
		for(var i = 0; i < iRow; i++ ){
			
			title[i] = list[i].CCTVNAME;
			
			points[i] = [list[i].YCOORD, list[i].XCOORD, list[i].CCTV_IP, list[i].STREAMINGSESSION, list[i].CCTVID, list[i].PORT ];
				
			img[i] = "cctv03.png"; //조병조수정 - 이미지 변경
			
		}
		
		markerRemove("cctv");
		
		//마커표출
		setMarker(points, title, "cctv", img , LARGECCTVSIZE);
		
	}else {
		
		showLoaderAll(false);
	}
}
/********************************************************************************
 * 고속도로 CCTV 조회
 ********************************************************************************/
var cctvRoadAjaxReq=null;
function getCctvRoad() { 
	
	if(cctvRoadAjaxReq!=null){
		if(cctvRoadAjaxReq.readyState == 1){
			cctvRoadAjaxReq.abort();
			cctvRoadAjaxReq = null;
		}
	}
	
	var flag = $("#roadCctv").attr("class");

	level = map.getLevel();
	
	if(level < CCTVE05_VIEW_LEVEL) {
		
		if(flag.indexOf("road_on") !== -1) {
			var option = {
					url		 : "main/getCctvRoad.do",
					param	 : {  MIN_X : $("#min_x").val()
								, MIN_Y : $("#min_y").val()
								, MAX_X : $("#max_x").val()
								, MAX_Y : $("#max_y").val()
								, IPFLAG : IPFLAG
								},
					callback : getCctvRoadCallback
				};
			
				
			cctvRoadAjaxReq = callService(option);
		
		} else {
			markerRemove("roadCctv");
			roadCctvClose();
		}
	}
}
/********************************************************************************
 * 고속도로 CCTV 조회 Callback
 * @param json
 ********************************************************************************/
function getCctvRoadCallback(json) { 
		
	var list = json.data.cctvRoadList;
	var iRow = list.length;
	
	var title 	= new Array();
	var lon 	= new Array();
	var lat 	= new Array();
	var id 		= new Array();
	var points 	= new Array();
	var img		= new Array();
	
	level = map.getLevel();
	
	if(iRow > 0) {
		
		for(var i = 0; i < iRow; i++ ){
			
			title[i] = list[i].CCTVNAME;
						
			//points[i] = [list[i].YCOORD, list[i].XCOORD, list[i].STRMID, list[i].CENTERID, list[i].CCTVID, list[i].PORT, list[i].CCTV_IP, list[i].STREAMINGSESSION];
			points[i] = [list[i].YCOORD, list[i].XCOORD, list[i].CCTV_IP, list[i].STREAMINGSESSION, list[i].CCTVID, list[i].PORT ];
			
			img[i] = "cctv01.png"; //조병조수정 - 이미지 변경
		}
		
		markerRemove("roadCctv");
		//마커표출
		setMarker(points, title, "roadCctv", img, LARGECCTVSIZE);
	
	}else {
		
		showLoaderAll(false);
	}
}
/********************************************************************************
 * 고속도로 CCTV 조회(도로공사 교통센터) 
 ********************************************************************************/
var cctvRoadE05AjaxReq=null;
function getCctvE05Road() { 
	
	if(cctvRoadE05AjaxReq!=null){
		if(cctvRoadE05AjaxReq.readyState == 1){
			cctvRoadE05AjaxReq.abort();
			cctvRoadE05AjaxReq = null;
		}
	}
	
	var flag = $("#roadCctvE05").attr("class");

	level = map.getLevel();
	
	if(level < CCTVE05_VIEW_LEVEL) {
		if(flag.indexOf("road_on") !== -1) {
			var option = {
					url		 : "main/getCctvRoadE05.do",
					param	 : {  MIN_X : $("#min_x").val()
								, MIN_Y : $("#min_y").val()
								, MAX_X : $("#max_x").val()
								, MAX_Y : $("#max_y").val()
								, IPFLAG : IPFLAG
								},
					callback : getCctvE05RoadCallback
				};
			
				cctvRoadE05AjaxReq = callService(option);
		
		} else {
			markerRemove("roadCctvE05");
			roadCctvE05Close();
		}
	}
}
/********************************************************************************
 * 국도 CCTV 조회 Callback
 * @param json
 ********************************************************************************/
function getCctvE05RoadCallback(json) { 
		
	var list = json.data.cctvRoadList;
	var iRow = list.length;
	
	var title 	= new Array();
	var lon 	= new Array();
	var lat 	= new Array();
	var id 		= new Array();
	var points 	= new Array();
	var img		= new Array();
	
	level = map.getLevel();

	if(iRow > 0) {
		
		for(var i = 0; i < iRow; i++ ){
			
			title.push(list[i].CCTVNAME);
						
			//points[i] = [list[i].YCOORD, list[i].XCOORD, list[i].STRMID, list[i].CENTERID, list[i].CCTVID, list[i].CH, list[i].KIND, list[i].PORT, list[i].CCTV_IP, list[i].STREAMINGSESSION];
			points[i] = [list[i].YCOORD, list[i].XCOORD, list[i].STRMID, list[i].CENTERID, list[i].CCTVID, list[i].PORT, list[i].CCTV_IP, list[i].STREAMINGSESSION];
			img[i] = "cctv02.png"; //조병조수정 - 이미지 변경
		}

		markerRemove("roadCctvE05");
		//마커표출
		setMarker(points, title, "roadCctvE05", img, LARGECCTVSIZE);
	
	}else {
		
		showLoaderAll(false);
	}
}
/********************************************************************************
 * 돌발 정보조회
*********************************************************************************/
function getIMS() {
	
	var flag = $("#ims").attr("class");
	
	var imsId = $("#imsId").val();
	
	level = map.getLevel();
	
	if(level < IMS_VIEW_LEVEL) {
		
		if(flag.indexOf("road_on") !== -1) {
			
			markerRemove("trouble");
			
			//타이머 호출 정지
			getImsTimerStop();
			
			//타이머 호출 시작
			imsTimer = setTimeout(function(){ getIMS() }, timerOne);
			
			var option = {
					url		 : "main/getIMS.do",
					param	 : {  MIN_X : $("#min_x").val()
								, MIN_Y : $("#min_y").val()
								, MAX_X : $("#max_x").val()
								, MAX_Y : $("#max_y").val()
								, INCIDENTID: imsId
								},
					callback : getIMSCallback
				};
			
				callService(option);
			
		}else {
			
			markerRemove("ims");
			markerRemove("imsLink");
			//타이머 호출 정지
			getImsTimerStop();
		}
	}
}
function getIMSCallback(json) {
	if($("#ims").attr("class").indexOf("road_on") === -1){
		return;
	}
	
	var list = json.data.imsList;
	var iRow = list.length;
	
	var points	= new Array();
	var img		= new Array();
	var title	= new Array();
	
	var LOCATION_TYPE_CD = "";
	var INCIDENT_GRADE_CD = "";	//돌발등급
	var INCIDENT_TYPE_CD = "";	//5일 경우 전면통제
	var INCIDENT_INSERT_CD = "";
	
	level = map.getLevel();
	
	if(iRow > 0) {
		
		if(level > 6) {
		//	showLoaderAll(true);
		}
		
		for(var i = 0; i < iRow; i++ ){
			
			LOCATION_TYPE_CD 	= list[i].LOCATION_TYPE_CD ;
			INCIDENT_GRADE_CD 	= list[i].INCIDENT_GRADE_CD;
			INCIDENT_INSERT_CD 	= list[i].INCIDENT_INSERT_CD;
			INCIDENT_TYPE_CD	= list[i].INCIDENT_TYPE_CD;
			
			if(LOCATION_TYPE_CD == "C0101"){
				
				if(INCIDENT_GRADE_CD == "A0401"){
					
					if(INCIDENT_INSERT_CD == "G"){
						
						img[i] = "btn_roadDanger.png";
						
					}else if(INCIDENT_TYPE_CD == "1"){
						
						img[i] = "btn_accident_A.gif";
						
					}else if(INCIDENT_TYPE_CD == "2"){
						
						img[i] = "btn_repair_A.gif";
						
					}else if(INCIDENT_TYPE_CD == "3"){
						
						img[i] = "btn_event_A.gif";
						
					}else if(INCIDENT_TYPE_CD == "4"){
						
						img[i] = "btn_alert_A.gif";
						
					}else if(INCIDENT_TYPE_CD == "5"){
						
						img[i] = "btn_trouble_A.gif";
					}
					
				}else{
					
					if(INCIDENT_INSERT_CD == "G"){
						
						img[i] = "btn_roadDanger.png";
						
					}else if(INCIDENT_TYPE_CD == "1"){
						
						img[i] = "btn_accident.png";
						
					}else if(INCIDENT_TYPE_CD == "2"){
						
						img[i] = "btn_repair.png";
						
					}else if(INCIDENT_TYPE_CD == "3"){
						
						img[i] = "btn_event.png";
						
					}else if(INCIDENT_TYPE_CD == "4"){
						
						img[i] = "btn_alert.png";
						
					}else if(INCIDENT_TYPE_CD == "5"){
						
						img[i] = "btn_trouble.png";
					}else if(INCIDENT_TYPE_CD == "6"){
            
            img[i] = "btn_disaster.gif";
          }else if(INCIDENT_TYPE_CD == "9"){
            
            img[i] = "btn_alert_9.png";
          }
					
				}
		
			}else if(LOCATION_TYPE_CD == "C0102"){
				
				if(INCIDENT_GRADE_CD == "A0401"){
					
					if(INCIDENT_TYPE_CD == "1"){
						
						img[i] = "btn_accident_A.gif";
						
					}else if(INCIDENT_TYPE_CD == "2"){
						
						img[i] = "btn_repair_A.gif";
						
					}else if(INCIDENT_TYPE_CD == "3"){
						
						img[i] = "btn_event_A.gif";
						
					}else if(INCIDENT_TYPE_CD == "4"){
						
						img[i] = "btn_alert_A.gif";
						
					}else if(INCIDENT_TYPE_CD == "5"){
						
						img[i] = "btn_trouble_A.gif";
					}else if(INCIDENT_TYPE_CD == "6"){
            
            img[i] = "btn_disaster.gif";
          }else if(INCIDENT_TYPE_CD == "9"){
            
            img[i] = "btn_alert_9.png";
          }
          
					
				}else{
					
					if(INCIDENT_TYPE_CD == "1"){
						
						img[i] = "btn_accident.png";
						
					}else if(INCIDENT_TYPE_CD == "2"){
						
						img[i] = "btn_repair.png";
						
					}else if(INCIDENT_TYPE_CD == "3"){
						
						img[i] = "btn_event.png";
						
					}else if(INCIDENT_TYPE_CD == "4"){
						
						img[i] = "btn_alert.png";
						
					}else if(INCIDENT_TYPE_CD == "5"){
						
						img[i] = "btn_trouble.png";
					}else if(INCIDENT_TYPE_CD == "6"){
            
            img[i] = "btn_disaster.gif";
          }else if(INCIDENT_TYPE_CD == "9"){
            
            img[i] = "btn_alert_9.png";
          }
				}
			
			}else if(LOCATION_TYPE_CD == "C0103"){
			
				if(INCIDENT_GRADE_CD == "A0401"){
					if(INCIDENT_TYPE_CD == "1"){
						img[i] = "btn_accident_A.gif";
					}else if(INCIDENT_TYPE_CD == "2"){
						img[i] = "btn_repair_A.gif";
					}else if(INCIDENT_TYPE_CD == "3"){
						img[i] = "btn_event_A.gif";
					}else if(INCIDENT_TYPE_CD == "4"){
						img[i] = "btn_alert_A.gif";
					}else if(INCIDENT_TYPE_CD == "5"){
						img[i] = "btn_trouble_A.gif";
					}else if(INCIDENT_TYPE_CD == "6"){
            img[i] = "btn_disaster.gif";
          }else if(INCIDENT_TYPE_CD == "9"){
            img[i] = "btn_alert_9.png";
          }
					
				}else{
					if(INCIDENT_TYPE_CD == "1"){
						img[i] = "btn_accident.png";
					}else if(INCIDENT_TYPE_CD == "2"){
						img[i] = "btn_repair.png";
					}else if(INCIDENT_TYPE_CD == "3"){
						img[i] = "btn_event.png";
					}else if(INCIDENT_TYPE_CD == "4"){
						img[i] = "btn_alert.png";
					}else if(INCIDENT_TYPE_CD == "5"){
						img[i] = "btn_trouble.png";
					}else if(INCIDENT_TYPE_CD == "6"){
            img[i] = "btn_disaster.gif";
          }else if(INCIDENT_TYPE_CD == "9"){
            img[i] = "btn_alert_9.png";
          }
				}
			}
			
			
			//결과값 배열
			points[i] = [list[i].LOCATION_DATA_Y, list[i].LOCATION_DATA_X, list[i].INCIDENT_ID,
			             list[i].INCIDENT_TYPE_CD, list[i].INCIDENT_TITLE, list[i].INCIDENT_REPORT,
			             list[i].START_DATE, list[i].END_DATE,list[i].IMS_IMAGES_PATH, list[i].LOCATION_DATA];
			
			title[i]  = "돌발정보";
		}
		markerRemove("ims");
		markerRemove("imsLink");
		//마커표출
		setMarker(points, title, "ims", img, 50);
		//링크표출
    setLink(points);
		
	}else {
		
		showLoaderAll(false);
	}
}
/********************************************************************************
 * 위치검색
*********************************************************************************/
function getSearch() {
	
	var place = $("#place").attr("class");
	
	if(place.indexOf("road_off") !== -1) {
		
		markerRemove("search");
		$("#keyword").val("");
		$("#menu_wrap").css("display", "none");
		
	}else {
		
		$("#menu_wrap").css("display", "block");
		$("#keyword").focus();
	}
}
/********************************************************************************
 * 신호현시표시
*********************************************************************************/
function getIntSig() {
	
	var intSig = $("#intSig").attr("class");
	
	if(intSig.indexOf("road_off") !== -1) {
		if(sigInfowindow != null) sigInfowindow.close();
		//모바일 팝업갱신 클리어
	    if(getSigPopMobId != null) clearInterval(getSigPopMobId);
	    
		clearInterval(getPhaseTimeId);
		
		if(signalArr != null)
		{
			signalArr.forEach(function(el) {
				el.mapCircle.setMap(null);
			});
			
			signalArr = 0;
			signalArr = [];
		}
		
		emptySignalArr(signalBackCircleArr);
		emptySignalArr(signalALineArr);
		emptySignalArr(signalBLineArr);
		
		signalBackCircleArr = [];
		aRingPhaseArr    = [];
		bRingPhaseArr    = [];
		
		closeMobInfo();
		$('.sigInfoBox').hide();
	}else {
		this.level = map.getLevel();
		if(this.level < 6){
			_mapSignal = new HashMap();
			mapSigZoomBound();
			$('.sigInfoBox').show();
		}else{
			//alert('6레벨 이상에서는 보이지 않습니다.');
		}
	}
	var fooDp = $('#foo').css('display');
	if(fooDp == 'block')
		$('.mylocationMob').css('bottom','130px');
	else 
		$('.mylocationMob').css('bottom','70px');
}
/********************************************************************************
 * obeId 버튼클릭
*********************************************************************************/
function getObeSearch() {
	//console.log('search!!');
	
	var obeClass = $("#obdId").attr("class");
	
	var obeKeyword = nvl($("#obeKeyword").val(), "");
	
	if(obeKeyword == "") {
		
		alert("OBE ID를 입력해주세요.");
		$("#obeKeyword").focus();
		
		if(obeClass.indexOf("road_on") !== -1) {
			//타이머 호출 정지
			getObeTimerStop();
		}
		
		return;
	
	}else {
		
		getObeTimerStop();
		
		$("#obdId").attr("class","road_on");
		$("#obdId").attr("src", BTN_IMAGE_PATH + "btn_obdon.gif");
		
		markerRemove("obeId");
		
		//getObeTimerStart();
		
		//타이머 호출 시작
		obeTimer = setTimeout(function(){ getObeSearch() }, timerOne);
		
		var option = {
						url		 : "main/getObeId.do",
						param	 : {  OBEID : obeKeyword  },
						callback : getObeSearchCallback
					};
			
					callService(option);
	}
}

function getObeSearchCallback(json) {
	
	var list = json.data.resultList;
	var iRow = list.length;
	
	var obeKeyword = nvl($("#obeKeyword").val(), "");
	
	if(iRow > 0) {
		
		var points	= new Array();
		var img		= new Array();
		var title	= new Array();
		
		//결과값 배열
		for(var i = 0 ; i< iRow; i++) {
			
			points[i] = [list[i].COORDY, list[i].COORDX, list[i].OBEID,
			             list[i].GPSTM];
			
			title[i]  = "OBEID";
			
			img[i] = "obeIcon.png";
		}
		//결과값을 지도 중심으로 표출
		setBounds(list[0].COORDY,list[0].COORDX, 6);
		
		setMarker(points, title, "obeId", img, 50); 
	}
}
/********************************************************************************
 * OBEID road_on일 경우 5분마다 호출
*********************************************************************************/
function getObeTimerStart() {
	
	var obeKeyword = nvl($("#obeKeyword").val(), "");
	
	if(obeKeyword != "") {
		if($("#obdId").attr("class").indexOf("road_on") !== -1) {
			//console.log('timer start!');
			//타이머 호출 시작
			//obeTimer = setTimeout(function(){ getObeSearch() }, timerFive);
			getObeSearch();
			
		}else {
			//console.log('timer stop!');
			//타이머 호출 정지
			getObeTimerStop();
			
			$('#obeKeyword').val('');
			markerRemove("obeId");
			getObeTimerStop();
		}
	} else {
		
		alert('OBEID를 입력하세요.');
		
		$("#obdId").attr("class","road_off");
		$("#obdId").attr("src", BTN_IMAGE_PATH + "btn_obd.gif");
		$('#obeKeyword').focus();
		
		return;
	}
	
	
	/*if(($("#obdId").attr("class").indexOf("road_on") !== -1) && (obeKeyword != "")) {
		
		console.log('timer start!');
		//타이머 호출 시작
		//obeTimer = setTimeout(function(){ getObeSearch() }, timerFive);
		getObeSearch();
		
	}else {
		console.log('timer stop!');
		//타이머 호출 정지
		getObeTimerStop(); 
	}*/
}
/********************************************************************************
 * OBEID 타이머 호출 정지
*********************************************************************************/
function getObeTimerStop() {
	if(obeTimer != null) {
		clearTimeout(obeTimer);
		obeTimer = null;
	}
}
/********************************************************************************
 * 돌발 타이머 호출 정지
*********************************************************************************/
function getImsTimerStop() {
	
	if(imsTimer != null) {
		clearTimeout(imsTimer);
		imsTimer = null;
	}
}
/********************************************************************************
 * 푸터display
*********************************************************************************/
function getFooterBtn(obj) {
	
	//푸터숨기기
	if(obj == "A") {
		
		$("#foo2").css("display", "none");
		$("#foo").css("display", "block");
		
		$('.mylocationMob').css('bottom','130px');
	
	//푸터보이기	
	}else {
		
		$("#foo").css("display", "none");
		$("#foo2").css("display", "block");
		
		$('.mylocationMob').css('bottom','70px');
		
	}
	
	relocateTrafficInfoBox();
}

/********************************************************************************
 * 소통정보 기준시간 표출
*********************************************************************************/
function changeTimeDisplay() {
	var option = {
		url		 : "main/getTrafficUpdateTime.do",
		callback : function(json){
			if('undefined' === typeof(json) || null === json || 
				'undefined' === typeof(json.time) || 	null === json.time)
			
			var orgStr = json.data;
			var year = orgStr.substr(0, 4);
			var month = orgStr.substr(4, 2);
			var date = orgStr.substr(6, 2);
			var hour = orgStr.substr(8, 2);
			var minute = orgStr.substr(10, 2);
			var dateStr = year + '.' + month + '.' + date + ' ' + hour + ':' + minute;
			
			$('#divTrafficGenerateInfo').html('기준 : ' + dateStr);
		},
	};

	callService(option);
}

/********************************************************************************
 * 소통정보 상세기준 툴팁 감추기/보이기
*********************************************************************************/
function trafficInfoBoxPop(a) {
	if (a == 1) {
		$("#trafficPopTrafficGoods").toggle();
		$("#trafficPopTrafficNormal").hide();
		$("#trafficPopTrafficBad").hide();
	} else if (a == 2) {
		$("#trafficPopTrafficNormal").toggle();
		$("#trafficPopTrafficGoods").hide();
		$("#trafficPopTrafficBad").hide();
	} else if (a == 3) {
		$("#trafficPopTrafficBad").toggle();
		$("#trafficPopTrafficGoods").hide();
		$("#trafficPopTrafficNormal").hide();
	} else if (a == 0) {
		$("#trafficPopTrafficBad").hide();
		$("#trafficPopTrafficGoods").hide();
		$("#trafficPopTrafficNormal").hide();
	}
	
}

/********************************************************************************
 * 소통정보 범례 감추기
*********************************************************************************/
function trafficInfoBoxClose() {
	$("#trafficInfoBox").hide();
}

/********************************************************************************
 * 소통정보 범례 위치 재조정
*********************************************************************************/
function relocateTrafficInfoBox() {
	var footerDiv = $("#foo").css("display");
	// 푸터가 표출되는경우
	if(footerDiv=='block'){
		$("#trafficInfoBox").css("bottom","65px"); 
		$(".sigInfoBox").css("bottom","65px");
	// 푸터가 감춰진경우
	}else{
		$("#trafficInfoBox").css("bottom","5px");
		$(".sigInfoBox").css("bottom","5px");
	}
}

/********************************************************************************
 * 현재위치 찾기
*********************************************************************************/
function getMyLocation(){
	if (navigator.geolocation) {
		var geo_options = {
			    enableHighAccuracy: false, // 불리언
			    maximumAge        : 0, // 천분의 1초 단위
			    timeout           : 5000 // 천분의 1초 단위
			};

        navigator.geolocation.getCurrentPosition(showPosition, showError, geo_options);
    } else {
        alert("Geolocation is not supported by this browser.");
    }
}

function geoTestCallback() {
	
}

function showPosition(position) {
	var crd = position.coords;
	//alert('crd : '+crd);
	var myCenter = null;
	myCenter = new daum.maps.LatLng(position.coords.latitude, position.coords.longitude);
    map.setCenter(myCenter);
    mapMoveBound();
    	detectAddMarker(myCenter,1);
}

function showError(error) {
	var errMsg='';
	//tryAPIGeolocation();
    switch(error.code) {
        case error.PERMISSION_DENIED:
        	errMsg = "User denied the request for Geolocation."; 
            break;
        case error.POSITION_UNAVAILABLE:
        	errMsg = "Location information is unavailable.";
            break;
        case error.TIMEOUT:
        	errMsg = "The request to get user location timed out.";
            break;
        case error.UNKNOWN_ERROR:
        	errMsg = "An unknown error occurred.";
            break;
    }
    alert(errMsg);
}

var tryAPIGeolocation = function() {
    $.post( "https://apis.daum.net/maps/maps3.js?apikey=3f46a15893f17f41a6efd43db29ef3ee&libraries=services,clusterer", function(success) {
        //apiGeolocationSuccess({coords: {latitude: success.location.lat, longitude: success.location.lng}});
    	alert('lat : '+success.location.lat);
  }).fail(function(err) {
    alert("API Geolocation error! \n\n"+err);
	  //alert(err);
  });
};

function getSidoGrpName(sidoCode){
	if(sidoCode=='01') 		return '특별/광역/자치도';
	else if(sidoCode=='02') return '경기권';
	else if(sidoCode=='03') return '경상권';
	else if(sidoCode=='04') return '전라권';
	else if(sidoCode=='05') return '충청권';
	else if(sidoCode=='06') return '강원권';
	else return '';
}

/********************************************************************************
 * 모바일 버전 cctv 토글 버튼
*********************************************************************************/
function getCCTV_m(){
	$('#cctv').toggleClass('road_on road_off');
	getCCTV();
}

function getCctvRoad_m(){
	$('#roadCctv').toggleClass('road_on road_off');
	getCctvRoad();
}

function getCctvE05Road_m(){
	$('#roadCctvE05').toggleClass('road_on road_off');
	getCctvE05Road();
}

/********************************************************************************
 * Image lazyload
*********************************************************************************/
document.addEventListener("DOMContentLoaded", function() {
  var lazyloadImages;    

  if ("IntersectionObserver" in window) {
    lazyloadImages = document.querySelectorAll(".lazy");
    var imageObserver = new IntersectionObserver(function(entries, observer) {
      entries.forEach(function(entry) {
        if (entry.isIntersecting) {
          var image = entry.target;
          image.classList.remove("lazy");
          imageObserver.unobserve(image);
        }
      });
    });

    lazyloadImages.forEach(function(image) {
      imageObserver.observe(image);
    });
  } else {  
    var lazyloadThrottleTimeout;
    lazyloadImages = document.querySelectorAll(".lazy");
    
    function lazyload () {
      if(lazyloadThrottleTimeout) {
        clearTimeout(lazyloadThrottleTimeout);
      }    

      lazyloadThrottleTimeout = setTimeout(function() {
        var scrollTop = window.pageYOffset;
        lazyloadImages.forEach(function(img) {
            if(img.offsetTop < (window.innerHeight + scrollTop)) {
              img.src = img.dataset.src;
              img.classList.remove('lazy');
            }
        });
        if(lazyloadImages.length == 0) { 
          document.removeEventListener("scroll", lazyload);
          window.removeEventListener("resize", lazyload);
          window.removeEventListener("orientationChange", lazyload);
        }
      }, 20);
    }

    document.addEventListener("scroll", lazyload);
    window.addEventListener("resize", lazyload);
    window.addEventListener("orientationChange", lazyload);
  }
})