jQuery(function() {
	
	/*
   	---------------------------
   	Pre-Order Form
   	---------------------------
   	*/
   	
   	$('#preorder-formarea').hide();
   	$('a.preorder-confirm').click( function() {
   		$('#preorder-confirm-area').slideUp(300, function() {
   			$(this).remove();
   			$('#preorder-formarea').show(300);
   		});
   		return false;
   	});
	
	$('a.add-record').click( function() {
		var record = $(this).parents('li');
		record.clone(true).appendTo( $(record).parents('ul') ).find('a.remove-record:hidden').show().end().find('input:text').clearFields();
		return false;	
	});
	
	$('a.remove-record').click( function() {
		$(this).parents('li').remove();
		return false;
	});
	
	function confirmOrder(formData) {
		if(confirm('Confirm this order?')) {
			return true;
		}
		return false;
	}
	
	$('#orderform').ajaxForm({
		beforeSubmit: confirmOrder,
		dataType: 'json',
		success: function(d) {
			if(d.error) {
				alert(d.msg);
			} else {
				$('#preorder-formarea').hide(300);
				$('#preorder-thanks').append(d.msg).show(300);
			}
		}
	});
	
});