/*
	wca_scripts.js
	
	Javascripts for managing data in the wca ecommerce plugin for WordPress.
	These scripts require jQuery.
	
	If jQuery is not preloaded, the script will wait until the page finishes loading.
	If jQuery is flat-out not available, the script will load jQuery from the canonical Google location.
*/

/*
	Cart tasks to script
	# Remove item when 'Clear' icon is clicked
	# Remove item when quantity is zeroed out
	# Redraw cart (renumbering rows and etc.) when any cart-related event occurs.
	# Recalculate cart (Price hover value and subtotal and shipping) when any cart-related event occurs
	
	Session tasks to script (is AJAX needed?)
	# Rewrite cart session when cart is updated (quantity is changed, item removed)
	# Rewrite cart session when "Add" item is clicked
	# Read cart session to recalculate cart and modify buttons as needed.
*/

function wca_initialize_cart() {
	$('.wca_quantity input').keyup(function() {
		$('#wca_message').html("<p>Press enter to change the quantity</p>").show().fadeOut(10000);
		$(this).parents('.wca_item').addClass('wca_highlight');
	}).change();
	// the following only operates if 'collapse_cart' is set.
	$('#wca_collapsed').css('display','block');
	$('#wca_expanded').css('display','none');
	$('#wca_clicktoexpand').mouseup(function() {
		$('#wca_collapsed').css('display','none');
		$('#wca_expanded').css('display','block');
	});
	$('#wca_clicktoclose').mouseup(function() {
		$('#wca_collapsed').css('display','block');
		$('#wca_expanded').css('display','none');
	});
}

// variable display for debugging. Requires jquery
function vt() {
	if (!document.getElementById('debug')) { return; }
	var bar = vt.arguments;
	var foo = new Array();
	for (a=0;a<bar.length;a++) {
		foo[a] =  '<span style="color:#900;">'+a+' => '+bar[a].toString();
	}
	$('#debug').html('<tt>'+foo.join(' <br /> ')+'</tt>');
	return;
}

// there has to be a test written into the html page to check for prior existence of jquery...
$(document).ready(function () {
	wca_initialize_cart(); // adds Javascript attributes and event handlers to DOM elements
});


/* EOF */

