jQuery(function(){
	jQuery('table[name*=addtobasket_area_]').each(function(){
		var a = jQuery('a', this);
		
		a[0].onclick = function() { return false; }
		
		a
		.unbind('click')
		.click(function(){
			var id = this.id.substr(2);
			var input = jQuery('#i_' + id)[0];
			var cnt = input.value.length && !isNaN(input.value) ? parseInt(input.value) : 1;
			umiBasket.getInstance().addElement(id, cnt);
			
			setTimeout(function(){
				jQuery.get('/eshop/basketInfo', {}, function(data, textStatus){
					jQuery('body').append(data);
				})
			}, 1500);
			
			return false;
		});
	});
	
	jQuery('input[id^=compare_]').each(function(){
		jQuery('a', jQuery(this).parent()).hide();
		jQuery(this).after('<label for="' + this.id + '" style="color: #4E88C7; cursor: pointer;">Сравнить</label>');
	});
	
	var comp_sel = jQuery('#compare_selected');
	if (comp_sel.length) {
		comp_sel[0].onclick = function() { return false; }
		
		comp_sel
		.unbind('click')
		.click(function(){
			var checkboxes = jQuery('input[id^=compare_]').filter('[checked]');
			
			if (checkboxes.length == 0) return false;
			
			ids = "";
			for (var i = 0; i < checkboxes.length; i++) {
				ids += checkboxes[i].id.substr("compare_".length) + ",";
			}
			
			jQuery.post('/eshop/mod_addToCompare', {checked:ids}, function(data, textStatus){
				jQuery('body').append(data);
			});
			
			
			return false;
		});
	}
});