function number_format( number, decimals, dec_point, thousands_sep ) {
	var i, j, kw, kd, km;
	if( isNaN(decimals = Math.abs(decimals)) ){	decimals = 2;}
	if( dec_point == undefined ){dec_point = ",";}
	if( thousands_sep == undefined ){thousands_sep = ".";}
	i = parseInt(number = (+number || 0).toFixed(decimals)) + "";
	if( (j = i.length) > 3 ){j = j % 3;} else{j = 0;}
	km = (j ? i.substr(0, j) + thousands_sep : "");
	kw = i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thousands_sep);
	kd = (decimals ? dec_point + Math.abs(number - i).toFixed(decimals).replace(/-/, 0).slice(2) : "");
	return km + kw + kd;
}


$(document).ready(function(){

	$(".add-basket").mouseout(function(){
		$(this).css('background-color','');
	}).mouseover(function(){
		$(this).css('background-color','#f7c100');
	});
	
	$(".add-basket").click(function() {
		var tovar = $(this).attr('id').substr(4);
		var cost = parseInt($("#cost"+tovar).html().split(" ").join(''));
		
		$.post('/inc/ajax-basket-add.php',{tovar:tovar,cost:cost},function(data){
			if (data == 'OK') {
			var num = parseInt($("#b_num").html());
			var sum = parseInt($("#b_summ").html().split(" ").join(''));
				
			$("#b_num").empty().append(num + 1);
			$("#b_summ").empty().append(number_format(sum + cost,0,'',' '));		
			
			alert('Товар добавлен в корзину');
			} else { alert(data); }
		
		});
	});
	
	
	$(".basket-del").click(function(){
		if (confirm('Вы действительно хотите удалить товар из корзины?')) {
			$.post('/inc/ajax-basket-del.php',{ id: $(this).attr('id').substr(4) },function(data){if(data!='OK'){alert(data);} else { document.location = document.location; }});
		}
	});
	
	
	
});
