
$(document).ready(function(){
	// tab 
	$('.tab_type01 a').click(function (e) {
		var contentid = $(this).attr('title');
		e.preventDefault();
		
		$('.tab_type01 .active').removeClass('active');
		$(this).addClass('active');
		$('.tab_view_box').removeClass('block');
		$('#' + contentid).addClass('block');

		$('.owl-carousel.loan_rate_sgroup').trigger('to.owl.carousel', 0);
		$('.loan_rate ._foldingWrapper').removeClass('active');
	});

	// content slide.
	var loanTotalOwl = $('.owl-carousel.type_total');
	var loanBankOwl = $('.owl-carousel.type_bank');
	var loanSavingsbankOwl = $('.owl-carousel.type_savingsbank');
	var loanInsuranceOwl = $('.owl-carousel.type_insurance');

	loanTotalOwl.owlCarousel({
		items:1,
		loop: false,
		nav: false,
		dots: false,
		mouseDrag: false,
		touchDrag: false,
		onInitialized  : counter,
		onTranslated : counter
	});

	loanBankOwl.owlCarousel({
		items:1,
		loop: false,
		nav: false,
		dots: false,
		mouseDrag: false,
		touchDrag: false,
		onInitialized  : counter,
		onTranslated : counter
	});

	loanSavingsbankOwl.owlCarousel({
		items:1,
		loop: false,
		nav: false,
		dots: false,
		mouseDrag: false,
		touchDrag: false,
		onInitialized  : counter,
		onTranslated : counter
	});

	loanInsuranceOwl.owlCarousel({
		items:1,
		loop: false,
		nav: false,
		dots: false,
		mouseDrag: false,
		touchDrag: false,
		onInitialized  : counter,
		onTranslated : counter
	});

	$('.loan_rate .owl_prev_btn').click(function() {
		$(this).closest('.tab_view_box').find('.owl-carousel.loan_rate_sgroup').trigger('prev.owl.carousel');
	});

	$('.loan_rate .owl_next_btn').click(function() {
		$(this).closest('.tab_view_box').find('.owl-carousel.loan_rate_sgroup').trigger('next.owl.carousel');
	})

	function counter(event) {
		var element   = event.target;
		var items     = event.item.count;
		var item      = event.item.index + 1;

		if(item > items) {
			item = item - items
		}

		$(element).closest('.tab_view_box').find('.owl_counter').html("<b>" + item + "</b> / " + items);
	}

	// 상세보기 & 월평균상환액 tab.
	$('.loan_rate ul.list_detail .option_btn').click(function () {
		var isActive = $(this).parent('li._foldingWrapper').hasClass('active');

		$(this).closest('ul.list_detail').find('li._foldingWrapper').removeClass('active');

		if(!isActive) {
			$(this).parent('li._foldingWrapper').addClass('active');
		} else {
			$(this).parent('li._foldingWrapper').removeClass('active');
			
		}
	});

	$('.loan_rate .info_detail .bottom_area .btn_close').click(function () {
		$(this).closest('ul.list_detail').find('li._foldingWrapper').removeClass('active');
	});

});