var update_cart_count = function (count) {
	var cart_display = $('#shopping-cart-display');
	if (cart_display.find('#cart-count').length > 0) {
		//increment count (if it's a new item):
		$('#cart-count').fadeOut('fast', function() {
			$(this).html(count).fadeIn('fast');
		});
	} else {
		if (count > 0) {
			cart_display.fadeOut('fast', function() {
				$(this).html('<a class="cart" href="/view-bag"><span id="cart-count">' + count + '</span> item(s) in bag</a>').fadeIn('fast');
			});
		} else {
			cart_display.fadeOut('fast', function() {
				$(this).html('<span class="cart">Bag is empty</span>').fadeIn('fast');
			});
		}
	}
};

$(document).ready(function() {
    $.ajaxSetup({ cache: false });
	var cart_info = $.getJSON('/get-cart-count.json', function(data) {
		update_cart_count(data.count);
	});
});

// usage: log('inside coolFunc',this,arguments);
// paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
window.log = function(){
  log.history = log.history || [];
  log.history.push(arguments);
  if(this.console){
    console.log( Array.prototype.slice.call(arguments) );
  }
};
