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

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

// The function to do it all
function json_cart_slide(el) {
	json_cart_height = - ( $j(el).height() ) - 100 + 'px';
	$j(el).css({
		top: json_cart_height
		,display: 'block'
		,opacity: 0
	}).animate({
		top: '0px'
		,opacity: .99
	}, 1000);
	
	timer = setTimeout(function(){
		json_cart_fade_out(el);
	}, 2500);
	$j(el).hover(function(){
		clearTimeout(timer);
	}, function(){
		timer = setTimeout(function(){
			json_cart_fade_out(el);
		}, 1000);
	});
}


// Set a counter so we can avoid sliding the cart down on page load
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+' x $'+fc_price_each+'</span></li>';
};


function fc_Funsies() {
	// console.info('Postprocess');
	// Define your cart HTML
	fc_FoxyCart = '<ul>';
	for (i=0;i<FC.json.products.length;i++) {
	  // BEGIN DO NOT EDIT
	  fc_BuildFoxyCartRow(FC.json.products[i].name,FC.json.products[i].code,FC.json.products[i].options,FC.json.products[i].quantity,FC.json.products[i].price_each,FC.json.products[i].price);
	  // END DO NOT EDIT
	}
	fc_FoxyCart += '</ul>';
	// console.info(counter);

	// 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.products.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;
}

fcc.events.cart.postprocess.add(function(){
	setTimeout('fc_Funsies();', 1000);
});

