$(function() {
	// TODO: this should actually target the li so that it can be styled properly
	var $cartToggler = $('#micro-cart-tool a.cart');
	
	// initialize micro cart toggle
	$cartToggler.toggler({
		activeClass	: 'active',
		closeClass	: 'close',
		open	    : function() {
			localStorage.setItem('micro-cart-toggle', true);
		},
		close	    : function() {
			localStorage.removeItem('micro-cart-toggle');
		}
	});
	
	// open the stickytools if they were open last request
	if (localStorage.getItem('micro-cart-toggle')) {
		$cartToggler.toggler('toggle', { duration: 0 });
	}
	
	// make the microcart toggle closed before redirecting
	$('li.checkout-link a').click(function() {
		var checkoutLink = this;
		$cartToggler.toggler('toggle', {
			closeCallback: function() {
				localStorage.removeItem('micro-cart-toggle');
				window.location = checkoutLink.href;
			}
		});
		
		return false;
	});
});

