var DORCATEGORY = {
	init:function(){
		window.addEventListener('load', function (){
		    DORCATEGORY.AjaxLoadData();
		    
		});
	},
	ReloadProcess:function(){
		var html = "";
		html += '<div class="graph__preloader">';
	        html += '<div class="js-preloader preloader">';
	          html += '<b class="preloader__bar -bar1"></b>';
	          html += '<b class="preloader__bar -bar2"></b>';
	          html += '<b class="preloader__bar -bar3"></b>';
	          html += '<b class="preloader__bar -bar4"></b>';
	          html += '<b class="preloader__bar -bar5"></b>';
	        html += '</div>';
	    html += '</div>';
	    return html;
	},
	
	AjaxLoadData:function(){
		var checkAjax = jQuery(".tab_category_container").attr("data-ajaxload");
		var processHtml = DORCATEGORY.ReloadProcess();
		if(typeof checkAjax == "undefined") {
			DORCATEGORY.CarouselCategory();
			return false;
		}
		jQuery(".tab_category_container").css("min-height",365);
		jQuery(".tab_category_container .graph__preloader").remove();
		jQuery(".tab_category_container").append(processHtml);
		var urlAjax = jQuery(".tab_category_container").attr("data-ajaxurl");
		var params = {}
		jQuery.ajax({
            url: urlAjax,
            data:params,
            type:"POST",
            success:function(data){
            	setTimeout(function(){
            		var results = JSON.parse(data);
	            	jQuery(".tab_category_container .graph__preloader").remove();
	            	jQuery(".tab_category_container").html(results);
	            	jQuery(".tab_category_container").css("min-height","auto");
	            	DORCATEGORY.CarouselCategory();
					if(typeof DORTHEME != "undefined" && typeof DORTHEME.ToolTipBootstrap == "function"){
						DORTHEME.ToolTipBootstrap();
					}
					
					if(typeof DORTHEME.DorQuantity != "undefined" && typeof DORTHEME.DorQuantity == "function"){
	            		//DORTHEME.DorQuantity();
	            	}
					if(typeof DORTHEME != "undefined" && typeof DORTHEME.LazyLoad != "undefined" && typeof DORTHEME.LazyLoad == "function"){
	            		DORTHEME.LazyLoad();
	            	}
            	},300);
                return false;
            }
        });
	},
	CarouselCategory:function(){
		$('.lists_category').owlCarousel({
	        items: 5,
	        loop: true,
	        nav: false,
	        autoplay: true,
	        dots: true,
	        margin:20,
	        autoplaySpeed : 200,
	        autoplayTimeout : 4000,
			navSpeed : 200,
			dotsSpeed : 200,
			autoplayHoverPause: true,
	        responsive: {
	            0: {items: 1},
	            1500: {items: 5},
	            1400: {items: 4},
	            1200: {items: 4},
	            990: {items: 3},
	            850: {items: 3, margin:20},
	            530: {items: 2, margin:20},
	            300: {items: 1, margin:0}
	        },
	        onInitialize: function (event) {
		        if ($('.lists_category').find('li').length <= 1) {
		           this.settings.loop = false;
		        }
		    },
	        navText: ["<i class='fa fa-angle-left'></i>", "<i class='fa fa-angle-right'></i>"]
	    });
	},
}
jQuery(document).ready(function(){
	DORCATEGORY.init();
});