var DORVIEWED = {
	init:function(){
		DORVIEWED.CarouselViewed();
		DORVIEWED.CarouselDetailViewed();
		window.addEventListener('load', function (){
		    DORVIEWED.HomeLoadDefault();
		    DORVIEWED.ProductLoadDefault();
		});
	},
	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;
	},
	HomeLoadDefault:function(){
		var urlAjax = jQuery(".dor-viewedproducts-inner").attr("data-ajaxurl");
		if(typeof urlAjax == "undefined") return false;
		var processHtml = DORVIEWED.ReloadProcess();
		
		jQuery(".dor-viewedproducts-inner .dor-home-viewed-products-inner").css({
			"min-height":420,
			"max-height":420,
			"overflow":"hidden",
			"opacity":0,
			"visibility":"hidden"
		});
		
		jQuery(".dor-viewedproducts-inner .loaddingAjaxTab").remove();
		jQuery(".dor-viewedproducts-inner .graph__preloader").remove();
		jQuery(".dor-viewedproducts-inner").append(processHtml);
		var params = {};
		params.type = 0;
		jQuery.ajax({
            url: urlAjax,
            data:params,
            type:"POST",
            success:function(data){
            	var results = JSON.parse(data);
            	
            	jQuery(".dor-viewedproducts-inner .dor-viewedproducts-data").html(results);
            	
            	setTimeout(function(){
            		DORVIEWED.CarouselViewed();
            		jQuery(".dor-viewedproducts-inner .dor-home-viewed-products-inner").css({
						"min-height":"auto",
						"max-height":"none",
						"overflow":"hidden",
						"opacity":1,
						"visibility":"visible"
					});
            		jQuery(".dor-viewedproducts-inner .graph__preloader").remove();
            		jQuery(".loaddingAjaxTab").remove();
            	},200);
            	
				if(typeof DORTHEME != "undefined" && typeof DORTHEME.ToolTipBootstrap == "function"){
					DORTHEME.ToolTipBootstrap();
				}
                return false;
            }
        });
	},
	ProductLoadDefault:function(){
		var urlAjax = jQuery("#products-viewed .product-viewed-inner").attr("data-ajaxurl");
		if(typeof urlAjax == "undefined") return false;
		var processHtml = DORVIEWED.ReloadProcess();
		
		jQuery("#products-viewed .product-viewed-inner .product-viewed-wrapper").css({
			"min-height":420,
			"max-height":420,
			"overflow":"hidden",
			"opacity":0,
			"visibility":"hidden"
		});
		
		jQuery("#products-viewed .product-viewed-inner .loaddingAjaxTab").remove();
		jQuery("#products-viewed .product-viewed-inner .graph__preloader").remove();
		jQuery("#products-viewed .product-viewed-inner").append(processHtml);
		var params = {};
		params.type = 1;
		jQuery.ajax({
            url: urlAjax,
            data:params,
            type:"POST",
            success:function(data){
            	var results = JSON.parse(data);
            	
            	jQuery("#products-viewed .product-viewed-inner .product-viewed-data").html(results);
            	
            	setTimeout(function(){
            		DORVIEWED.CarouselDetailViewed();
            		jQuery("#products-viewed .product-viewed-inner .product-viewed-wrapper").css({
						"min-height":"auto",
						"max-height":"none",
						"overflow":"hidden",
						"opacity":1,
						"visibility":"visible"
					});
            		jQuery("#products-viewed .product-viewed-inner .graph__preloader").remove();
            		jQuery(".loaddingAjaxTab").remove();
            	},200);
            	
				if(typeof DORTHEME != "undefined" && typeof DORTHEME.ToolTipBootstrap == "function"){
					DORTHEME.ToolTipBootstrap();
				}
                return false;
            }
        });
	},
	CarouselViewed:function(){
		$('#dor_homeviewed .products.owl-carousel').owlCarousel({
	        items: 5,
	        loop: true,
	        nav: true,
	        autoplay: false,
	        dots: true,
	        margin:20,
	        responsive: {
	            0: {items: 1},
	            1500: {items: 5},
	            1200: {items: 5},
	            990: {items: 4},
	            768: {items: 3},
	            650: {items: 2, margin:20},
	            460: {items: 2, margin:20},
	            370: {items: 1, margin:20},
	            300: {items: 1, margin:0}
	        },
	        onInitialize: function (event) {
		        if ($('#dor_homeviewed .products').find('article').length <= 1) {
		           this.settings.loop = false;
		        }
		    },
	        navText: ["<i class='fa fa-angle-left'></i>", "<i class='fa fa-angle-right'></i>"]
	    });
	},
	CarouselDetailViewed:function(){
		$('.product-viewed-data .detail-products').owlCarousel({
	        items: 6,
	        loop: true,
	        nav: true,
	        autoplay: false,
	        margin:20,
	        responsive: {
	            0: {items: 1},
	            1500: {items: 6},
	            1200: {items: 5},
	            992: {items: 4},
	            650: {items: 3, margin:20},
	            370: {items: 2, margin:20},
	            300: {items: 1, margin:0}
	        },
	        onInitialize: function (event) {
		        if ($('.product-viewed-data .detail-products').find('article').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(){
	DORVIEWED.init();
});