$(document).ready(function(){

	$('.add_to_basket').click(function(){
		var meta = $(this).attr('rel');
		var info = meta.split('|');
		var product_id = info[0];
		var container_id = info[1];
		$.post(
			'index.php',
			'ajax=1&file_path=templates/basket.php&class_name=Basket&method_name=XAddItem&arguments[product_id]='+ product_id +'&arguments[sum]=1',
			function(data, status, xmlHttp){
				if(data.replace == 0) {
					$('#sum_price').html(data.sum_price);
					$('#small_cart p:first').html(data.total_items);
				} else {
					$('#small_cart').replaceWith(data.replace);
				}
				$('#'+container_id).animate({opacity: 0.5}, 500);
				$('a.add_to_basket[href*='+product_id+']').hide().next().show();
				var properties = {
					href: 'index.php?ajax=1&link=1&file_path=templates/basket.php&method_name=XRender&class_name=Basket',
					width: '640px', height: '90%', opacity: .6, overlayClose: false, open: true
				}
				$(document).colorbox(properties);
			}, 'json');
		return false;
	});

	$('#show_layer, a.add_to_basket[href=?page_id=12]').colorbox({href: 'index.php?ajax=1&link=1&file_path=templates/basket.php&method_name=XRender&class_name=Basket', width: '640px', height: '90%', opacity: 0, overlayClose: false });
});