$(document).ready(function() {	
	//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']);
						$('.recommendthis').removeClass('active');
						
						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);
				if($.trim(data) != 0) {
					setRecentViewedSlider();
					$(".recommendthis:first").click();
				}	
			}
		});	
	}
});
//slider for recommendations
function setRecommendationSlider(controls) { 
	$('.bxslider').bxSlider({
	  infiniteLoop: false,
	  hideControlOnEnd: true,
	  minSlides: 4,
	  controls: controls,
	  maxSlides: 4,
	  slideWidth: 235,
         nextText: ' ',
        prevText: ' ',
        pager: false,
      slideMargin:15
	});
}
//slider for recent viewed
function setRecentViewedSlider() { 
	$('.bxslider2').bxSlider({
	  mode: 'vertical',
	  infiniteLoop: false,
      pager: false,    
	  hideControlOnEnd: true,
	  minSlides: 3,
	  moveSlides:3,
	  maxSlides: 3,
	  slideWidth: 350,
        nextText: ' ',
        prevText: ' ',
	  slideMargin: 0
	});
}