(function ($) {
    $(document).ready(function(){



$('body').bind("ajaxSend", function(){
 $('#preview_loader').show();
 });



$('.remove-btn-popup').live('click',function() {
id = $(this).attr('data-cartid');
data = "cartid="+id;
$.ajax({
					url: '/cartpreview/index/remove',
					type: 'GET',
                    data: data,
					success: function(response) {
					   
updatePreview();

if(typeof IS_FISHEYE_AJAXCART != "undefined") {
updateCartTotal();
}

 }
});

});



$('.topcartbox').qtip({
     
      content: {
       text: $('#preview_loader_default').html(), // The text to use whilst the AJAX request is loading
     ajax: {
         url: '/cartpreview', // URL to the local file
         type: 'GET', // POST or GET
         data: {}, // Data to pass along with your request
         success: function(data, status) {
            this.set('content.text', data);
            $('#preview_loader').hide();
      }
    
    }
   },
   	position: {
		at: "bottom right",
		my: "top right"
	},
  
     hide:  {
      effect: function(offset) {
         $(this).hide(); // "this" refers to the tooltip
      },
     	fixed: true,
		delay: 200
   },
   
  show:  {
      effect: function(offset) {
         $(this).show(); // "this" refers to the tooltip
      },
      	fixed: true
   }
   

    

});



	
   
    



$('.addqty').live('click', function() {
  id = $(this).attr('data-id');
 data = "cartid="+id+"&math=add";
$.ajax({
					url: '/cartpreview/index/qty',
					type: 'GET',
                    data: data,
					success: function(response) {

updatePreview();

if(typeof IS_FISHEYE_AJAXCART != "undefined") {
updateCartTotal();
}

}
});
});



$('.minusqty').live('click', function() {
  id = $(this).attr('data-id');
 data = "cartid="+id+"&math=minus";
$.ajax({
					url: '/cartpreview/index/qty',
					type: 'GET',
                    data: data,
					success: function(response) {


updatePreview();


if(typeof IS_FISHEYE_AJAXCART != "undefined") {
updateCartTotal();
}
}
});
 
});



showCartPreview = function() {
    updatePreview();
    $('.topcartbox').qtip('toggle',true);
}

hideCartPreview = function() {
    $('.topcartbox').qtip('toggle',false);
}


updatePreview = function() {
$('.topcartbox').qtip('toggle', true);
obj = $('.topcartbox').qtip();
$('#preview_loader').show();

$.ajax({
					url: '/cartpreview',
					type: 'GET',
					success: function(response) {
obj.set('content.text', response);
$('#preview_loader').hide();
}
});



}



    		   
});

})(jQuery);
