
$(document).ready(function() {



	var $boxinput = $('.inBox input'); //인풋 활성화 이벤트
	var $boxselect = $('.inBox select');
	var $boxTextarea = $('.textareaBox textarea');

	$boxinput.each(function(){
		var $this = $(this);
		var $box = $this.parents('.inBox');
		$this.on('focusin', function(){
			$box.addClass('boxFocus');
		});
		$this.on('focusout', function(){
			$box.removeClass('boxFocus');
		});
	});

	$boxselect.each(function(){
		var $this = $(this);
		var $box = $this.parents('.inBox');
		$this.on('focusin', function(){
			$box.addClass('boxFocus');
		});
		$this.on('focusout', function(){
			$box.removeClass('boxFocus');
		});
	});

	$boxTextarea.each(function(){
		var $this = $(this);
		var $box = $this.parents('.textareaBox');
		$this.on('focusin', function(){
			$box.addClass('boxFocus');
		});
		$this.on('focusout', function(){
			$box.removeClass('boxFocus');
		});
	});



	$('.btn_pop').on('click', function(e){
		e.preventDefault();
		var thisClass = $(this).attr('class');
		var idNum = thisClass.substring(thisClass.length-2);
		var idPop = $('.pop_opne' + idNum);
		var popCont = $('.pop_opne' + idNum).find('.layerContent');

		if( idPop.hasClass('popType01')){
			openPopup(idPop);
			$('.close_btn' + idNum).on('click', function(){
				closePopup(idPop);
			});
		} else {
			openPopup02(idPop, function() {
				popCont.css('height', popCont.find('.popup').height());
				popCont.css('top', ($(window).height() / 2 ) - (popCont.find('.popup').height() / 2));
			});
			$('.close_btn' + idNum).on('click', function(){
				closePopup02(idPop);
			});
		}
	});


	//toggleCont
	$('.toggleCont > li > dl > dt button').on('click', function(){
		// 초기화
		//$(this).find('span').text('열기');
		$(this).parent().parent().parent().parent().siblings().removeClass('active');
		//$(this).parents('li').removeClass('active');

		if( $(this).parents('li').hasClass('active')== false){
			$(this).parents('li').addClass('active');
			$(this).parents('li').find('dd').hide();
			$(this).find('span').text('닫기');
		} else {
			$(this).parents('li').removeClass('active');
			$(this).parents('li').find('dd').show();
			$(this).find('span').text('열기');
			
		}
	});


});


/* 팝업 오픈 */
function openPopup(selector, callback) {

	createDim();
	$(selector).show();
	$(selector).css("position", "fixed");

	if(callback != null) {
		callback();
	}
}

/* dim 처리 함수 */
function createDim() {
	var dim = $("<div class='dim'></div>");
	$("#wrap").prepend(dim);
	$("html, body, .wrap02").addClass("overNo");
	$(".wrap02").off("touchmove").on("touchmove", function(e) {
		e.preventDefault();
	});
}
function dropDim() {
	$(".dim").remove();
	$("html, body, .wrap02").removeClass("overNo");
	$(".wrap02").off("touchmove").css("overflow","auto");
}
function closePopup(selector) {
	dropDim();
	$(selector).hide();
}
