$(document).ready(function() {
    var recentlyviewslider;
	//to load recommendations	
	var recommedPtds={};
	$(document).on( 'click', ".recommendthis", function() {
		var productid = $(this).attr('product_id');
		var clickedDiv = $(this);
		if(productid > 0) {
			if(typeof recommedPtds[productid] != 'undefined') {
				data = recommedPtds[productid];
				$('#recommend-outer-div').html(data['html']);
				$('.recommendthis').removeClass('active');
				clickedDiv.addClass('active');
				if(data['count'] > 5)	
					setRecommendationSlider(true);
				else 
					setRecommendationSlider(false);
			}
			else {	
				$.ajax({   
					type:'POST',
					beforeSend : function() {},
					data:'productid='+productid,
					dataType : 'json',
					
					url: GLOBAL_BASE_PATH+"/product/ajaxrecommendproducts/",
					success:function(data) {  
						recommedPtds[productid] = data;
						$('#recommend-outer-div').html(data['html']);
						
						clickedDiv.addClass('active');
						if(data['count'] > 5)	
							setRecommendationSlider(true);
						else 
							setRecommendationSlider(false);
							
						}
				});
			}
		} 
	});
	//call to load recent viewed items
	if ( $('#recent-viewed').length)	{ 
		$.ajax({
			type:'POST', 
			data:'currentProductID='+detailPageProductID,
			beforeSend : function() {},
			url: GLOBAL_BASE_PATH+"/product/ajaxrecentlyviewed/",
			success:function(data) {
				$('.recommend').html(data);
                 recentlyviewslider=$('.bxslider2').bxSlider({
                  infiniteLoop: false,
                  hideControlOnEnd: true,
                  minSlides: maxSlides,
                  moveSlides:maxSlides, 
                  maxSlides: maxSlides,
                  pager: false,
                  slideWidth: 300,
                  slideMargin: 1
                });
        
            }
		});	
	}

	//call to load recent viewed items

var maxSlides;
width = $(window).width();
if (width <= 480) {
    maxSlides = 2;
} 
else if (width <= 680){
    maxSlides = 3;
}
else if (width <= 1000){
    maxSlides = 4;
}
else if (width <=1200){
    maxSlides = 5;
}
else {
    maxSlides = 6;
}  
//slider for recommendations
$(window).resize(function() {
    var recentlyviewslider;
 width = $(window).width(); 
    
if (width <= 480) {
    maxSlides = 2;
} 
else if (width <= 680){
    maxSlides = 3;
}
else if (width <= 1000){
    maxSlides = 4;
}
else if (width <=1200){
    maxSlides = 5;
}
else {
    maxSlides = 6;
}
   
recentlyviewslider.reloadSlider({
	  infiniteLoop: false,
	  hideControlOnEnd: true,
	  minSlides: maxSlides,
	  moveSlides:maxSlides, 
	  maxSlides: maxSlides,
      pager: false,
	  slideWidth: 300,
	  slideMargin: 1
	});
});
//slider for recent viewed
});
    