
var _im = 1;
var _vm = null;
var _tm = 30000;
var _is = 1;
var _vs = null;
var _ts = _tm/5;
$(function() {
	function initSlide() {			
		showSlide(_im);
		
		_vm = setInterval(function(){	showSlide(_im); },_tm);
		
		$('.slider .slider-main-nav li').off('click').on('click',function() {
			_im = $(this).data('sequence');
			showSlide(_im);
			
			clearInterval(_vm);
			_vm = setInterval(function(){	showSlide(_im); },_tm);
		});
	}
	
	function initSubSlide(i) {		
		showSubSlide(i,1);
		
		clearInterval(_vs);
		_vs = setInterval(function(){	showSubSlide(i,_is); },_ts);
		
		$('.slider .point[data-parent="'+i+'"]').off('click').on('click',function(e) {
			if (!$(e.target).hasClass('slider-link') && !$(e.target).hasClass('slider-footer-item')	) {
				_is = $(this).data('sequence');
				_im = $(this).data('parent');				
				
				showSubSlide(_im, _is);
			
				clearInterval(_vs);
				_vs = setInterval(function(){	showSubSlide(_im,_is); },_ts);
			}
		});
		
		$('.slider .point[data-parent="'+i+'"] .slider-footer-item').off('click').on('click',function(e) {
			_is = $(this).data('sequence');
			_im = $(this).parent().parent().parent('.point').data('parent');				
			
			showSubSlide(_im, _is);
		
			clearInterval(_vs);
			_vs = setInterval(function(){	showSubSlide(_im,_is); },_ts);
		});
	}
	
	function showSlide(i) {
		var c = $('.slider .slider-main').length;	
			
		$('.slider .slider-main').removeClass('active');
		$('.slider .slider-main[data-sequence="'+i+'"]').addClass('active');
		
		$('.slider .slider-main-nav li').removeClass('active');
		$('.slider .slider-main-nav li[data-sequence="'+i+'"]').addClass('active');
		
		initSubSlide(i);
		
		_im++;
		if(_im > c) _im = 1;
	}
	
	function showSubSlide(i,s) {
		var $main = $('.slider-main[data-sequence="'+i+'"]');
		var style = ($main.hasClass('style-3')) ? 3 : (	($main.hasClass('style-2')) ? 2 : (	($main.hasClass('style-1')) ? 1 : 1	)	);		
		var c = $('.point[data-parent="'+i+'"]').length;
	
		var $point = $('.slider .point[data-parent="'+i+'"][data-sequence="'+s+'"]');		
		var img = $point.data('image');
		if(typeof img !== "undefined") {
			$main.find('.slider-preview').fadeOut();
			$main.find('.slider-preview').css('background-image','url(\''+img+'\')');
			$main.find('.slider-preview').fadeIn();
		}
		
		$('.slider .point[data-parent="'+i+'"]').removeClass('active');
		$('.slider .point[data-parent="'+i+'"][data-sequence="'+s+'"]').addClass('active');
		
		_is++;
		if(_is > c) _is = 1;
	}
	
	initSlide();
});