jQuery(function($) {

unbind_selections();
total();

function unbind_selections()
{	
	//	Remove from cart
	$("div#cart table tr td a[@title='Remove']").click( function(event) {
		var link		= $(this);
		var purchase_id	= $(this).attr("href");
		
		$.post( "/registration/ajax_cart_delete/" + purchase_id, {}, function (data) {
			if ( data.substr(0,1) == "!" )
			{alert(data.substr(1));}
			else
			{
				link.parents("tr").remove();
				check_duplicates();
				switch_rows();
				total();
			}
		});
		
		return false;
	});
}

function switch_rows()
{
	var swtch = "two";
	
	$("div#cart table tr").not( $("div#cart table tr#total_row") ).each(function(i) {
		if ( swtch == "two" ) { swtch = "one"; } else { swtch = "two"; }
		$(this).children("td").attr("class", swtch);
	});
}

function total()
{
	var total	= 0;
	
	$("div#cart table tr td a[@title='Remove']").each( function(i,n) {
		total	+= $(this).attr("rel") * 1;
	});
	
	$("div#cart table tr td#total").html("$ " + total.toFixed(2));
}

function check_duplicates()
{
	$("td#cart_duplicates").load( "/registration/ajax_duplicates" );
}

});
