// Set the fade in and fade out functions
function json_cart_fade_in(el) {
	$j(el).css({height: '260px', opacity: '0'}).animate({
		opacity: .99
	}, 1000, 'linear', function(){
		$j(el).css({height:'260px', opacity:'.99'});
	});
}
function json_cart_fade_out(el) {
	$j(el).animate({
		opacity: 0
	}, 1000, 'linear', function(){
		$j(el).css({height:'0px', opacity:'0'});
	});
}

// Set the mini-cart to fade in the json cart
$j(document).ready(function(){
	$j('#cart_mini_link').mouseover(function(){
		json_cart_slide($j('#cart_json'));
	});
});

// The function to do it all
function json_cart_slide(el) {
	json_cart_fade_in(el);
	
	timer = setTimeout(function(){
		json_cart_fade_out(el);
	}, 4000);
	$j(el).hover(function(){
		clearTimeout(timer);
	}, function(){
		timer = setTimeout(function(){
			json_cart_fade_out(el);
		}, 1500);
	});
}


// Set a counter so we can avoid sliding the cart down on page load
counter = 0;

function fc_BuildFoxyCart() {
	// Define your cart HTML
	fc_FoxyCart = '<ul>';
	for (i=0;i<fc_json.cart.length;i++) {
	  // BEGIN DO NOT EDIT
	  fc_BuildFoxyCartRow(fc_json.cart[i].product.name,fc_json.cart[i].product.code,fc_json.cart[i].product.options,fc_json.cart[i].product.quantity,fc_json.cart[i].product.price_each,fc_json.cart[i].product.price);
	  // END DO NOT EDIT
	}

	// fc_FoxyCart is a javascript variable that now holds your shopping cart data

	// if you have some products in your cart, why not display it?
	if (fc_json.cart.length > 0) {
	  $j("#cart_json_content").html(fc_FoxyCart);
	} else {
	  $j("#cart_json_content").html("");
	}
	
	if (counter != 0 ) json_cart_slide('#cart_json');
	counter += 1;
}

// This function is called by fc_BuildFoxyCart() for each product in your cart.
// Feel free to edit this function as needed to display each row of your cart.
function fc_BuildFoxyCartRow(fc_name,fc_code,fc_options,fc_quantity,fc_price_each,fc_price) {
	fc_FoxyCart += '<li> \
		<span class="name">'+fc_name+'</span> \
		<span class="quantity">'+fc_quantity+'&nbsp;x&nbsp;$'+fc_price_each+'</span> \
		</li> \
	';
}
