// JavaScript Document

function changeCategories(cat_id){
	$.post('/shopping_cart/ajax_get_category_products.php', {item_id: cat_id}, function(data){
		var html = JSON.parse(data);
		if(html){
			$('#product_list').html(html).show();
		}
	});
}

$(document).ready(function(){
	$('#category_select').change(function(){ changeCategories($(this).val()); });
	
	$('#product_submit').livequery('click', function(){
		if($(this).val() != ''){
			$.post(
				'/shopping_cart/ajax_add_prod_cat.php', 
				{ prod_id: $('#product_select').val(), cat_id: $('#category_select').val() }, 
				function(data){
					if(data){
						window.location = "/stockset/" + $('#product_select').val() + "/";
					}
					else alert('An error has occured.');
			});
		}
	});
	
	$('.remove_item').click(function(){
		var obj = $(this).closest('td');
		$.post('/shopping_cart/ajax_remove_item.php', {item_id: $(this).attr('rel')}, function(data){
			if(data !== 'false'){
				obj.fadeOut(100, function(){
					if(data == 0){
						obj.html('<td align="left">You have no items in your Lightbox.</td>');
						obj.fadeIn(300);
					}					
				});
			}
		});		
	});
});


