$(document).ready(function () {
	//팝업 슬라이드
	if ($('.popup-slick .popup-detail-slide').length > 4) {
		$('.popup-slick').slick({
			slidesToShow: 1,
			slidesToScroll: 1,
			autoplay: false,
			autoplaySpeed: 2000,
			variableWidth: true,
			arrows: true,
			accessibility: false,
			responsive: [{
				breakpoint: 768,
				settings: {
					centerMode: true,
					centerPadding: '20px',
					slidesToShow: 3,
					variableWidth: true,
				}
			}]
		});
	}
    // 슬라이드
	$(document).ready(function () {
		var slideTarget = $('.unit-list-slide');
		for (var i = 0; i < slideTarget.length; i++) {
			if (slideTarget[i].children.length > 2) {
				$('.unit-list-slide').eq(i).slick({
					arrows: false,
					dots: true,
					accessibility: false,
					infinite: true,
					centerMode: true,
					centerPadding: '20px',
					slidesToShow: 3,
					variableWidth: true,
					responsive: [{
						breakpoint: 1028,
						settings: {
							centerMode: true,
							centerPadding: '20px',
							slidesToShow: 1,
							variableWidth: true,
						}
					},
					{
						breakpoint: 480,
						settings: {
							arrows: false,
							centerMode: true,
							centerPadding: '40px',
							slidesToShow: 1
						}
					}
					]
				});
			} else {
				$('.unit-list-slide').eq(i).addClass('none-opacity');
				$('.unit-list-slide').eq(i).slick({
					arrows: false,
					dots: false,
					accessibility: false,
					infinite: true,
					centerMode: true,
					centerPadding: '20px',
					slidesToShow: 3,
					variableWidth: true,
					responsive: [{
						breakpoint: 1028,
						settings: {
							centerMode: true,
							centerPadding: '20px',
							slidesToShow: 1,
							variableWidth: true,
						}
					},
					{
						breakpoint: 480,
						settings: {
							arrows: false,
							centerMode: true,
							centerPadding: '40px',
							slidesToShow: 1
						}
					}
					]
				});
			}
		};
	});

});

var HTTP_AJAX = {
	send: function(url, reqJson, callback){
        $.ajax({
			url: url,
			type: 'POST',
            data:reqJson,
            success:function(res){
            	console.log("recv:"+JSON.stringify(res));
				if(res.header.resCd == "0000"){
					if (typeof callback !== "undefined") {
						callback(res);
					}
				}else {
					alert("정상적으로 처리되지 않았습니다.");
				}
            },
            error: function(xhr, status, e){
            	alert(e);
            }
        });
	},
	sendForm: function(url, formName, callback){
		var formObj = $("#"+formName);
        $.ajax({
			url: url,
			type: 'POST',
            data:formObj.serialize(),
            success:function(res){
            	console.log("recv:"+JSON.stringify(res));
				if(res.header.resCd == "0000"){
					if (typeof callback !== "undefined") {
						callback(res);
					}
				}else {
					alert("정상적으로 처리되지 않았습니다.");
				}
            },
            error: function(xhr, status, e){
            	alert(e);
            }
        });
	}
}

var PAGER = {
	create: function(pageDiv, totalPage, visiblePage, clickCallback){
		if(totalPage==0) return;
		$(pageDiv).twbsPagination({
	        totalPages: totalPage,
	        visiblePages: visiblePage,
	        initiateStartPageClick:false,
	        prev:'<span aria-hidden="true">&laquo;</span>',
	        next:'<span aria-hidden="true">&raquo;</span>',
	        first:'',
	        last:'',
	        onPageClick: function (event, page) {
	            if(clickCallback)clickCallback(page);
	        }
	    });
	},
	destroy: function(pageDiv){
		$(pageDiv).twbsPagination('destroy');
	}
}

var MENU = {
		alert: function(title, content, callback){
			$("#LAYER_ALERT  .title").html(title);
			$("#LAYER_ALERT  .popup-body p").html(content);

			$("#MODAL_BTN_OK").off("click").on("click", function(){
				if(callback) callback();
			});
			
			$("#LAYER_ALERT").insertAfter('.wrapper');
			setTimeout(function () {
				$("#LAYER_ALERT").addClass('show').removeClass('hide');
			}, 100);
			setTimeout(function () {
				$('.popup-inner', "#LAYER_ALERT").attr('tabindex', '0').focus();
			}, 300);
			bodyScroll(true, $('body').width());
		}
}

/**
 * jquery serializeObject 재정의
 */
$.fn.serializeObject = function(){
	var o = {};
	var a = this.serializeArray();
	$.each(a, function(){
		if(o[this.name]){
			if(!o[this.name].push){
				o[this.name] = [o[this.name]];
			}
			o[this.name].push(this.value || '');
		}
		else{
			o[this.name] = this.value || '';
		}
	});
	
	return o;
};

String.prototype.getByteLen = function(){
	var cnt = 0;
	for (var i = 0; i < this.length; i++){
		if (this.charCodeAt(i) > 127){
			cnt += 2;
		}
		else{
			cnt++;
		}
	}
	return cnt;
};
