jQuery.fn.sbacket = function(options) {
   var settings = jQuery.extend({
       autolist: 1,
       editmodif: 0,
       autocomplete: "on",
       change: ""
   }, options); 
   
   $(".cinp").change(function () {
	   var money=Number($(this).parents(".back_money").find(".bmoney").attr("rel"));
	   var count=Number($(this).val());
	   var id=$(this).parents(".backetlist").attr("rel");
	   var tthis=this;
	   
	   $(this).parents(".back_money").find(".bmoney").text(money*count);
	   refrash_money();	
	   
	   //Добавляем в сессию
	   $.post("/shop_backet/change_count", { id:  id,count: count},
			   function(data){	
		   			if (data.error!=undefined) {
		   				$.jGrowl(data.error, {
		   					theme: 'error',
		   					speed: 'slow',
		   					animateOpen: {height: "show"},
		   					animateClose: {height: "hide"}
		   				});
		   				
		   				if (data.count!=undefined) {
			   				count=data.count;	
			   				$(tthis).parents(".back_money").find(".bmoney").text(money*count);
			   				$(tthis).val(count);
			   				refrash_money(); //Пересчитываем обратно
		   				}
		   			}
		   			
		   			if (data.ok!=undefined){
		   				$.jGrowl(data.ok, {
		   					theme: 'ok',
		   					speed: 'slow',
		   					animateOpen: {height: "show"},
		   					animateClose: {height: "hide"}
		   				});
		   				
		   		  }
			
				}, "json");
	   
	   
	     
   });
   
   $ (".back_remove").click (function () {
	   $ (this).parent ("div").remove();
	   
	   refrash_money();	   
   });
   
 
   function refrash_money() {
	   //Пересчитываем количество денег
	   //получаем названия всех полей с ценами
	   var allmoney=0;
	   $(".backetlist").each(function () {
		   var alsumm=Number($(this).find(".bmoney").attr("rel"));
		   var alcount=Number($(this).find(".cinp").val());
		   allmoney=allmoney+(alsumm*alcount);
	   });
	   $("#itolgosumm").text(allmoney+' рублей');
   }
   
}
