function add_to_cart(add_prefix, in_prefix, ids) {
  
  // Show the cart info bar if it's hidden.
  if ($('#cart_info').css('display') == 'none') {
    $('#cart_info').show();
  }
  
  // have to rebind this because the element was destroyed by the ajax call...
  bindMiniCartView('#mini_cart_contents');
  
  $(ids).each(function() {
    $("." + add_prefix + this).hide();
    $("." + in_prefix + this).show();
  });

  // flash the cart.
  flash_cart();
}

function hide_cart_contents() {
  //$('#mini_cart_contents').qtip('api').hide();

  // this is just going to hide all the qtips because calling the api
  // seems to be throwing an error at the moment
  $('.qtip').hide();
  $('#cart_info').hide();
}

function remove_from_cart(new_content, add_prefix, in_prefix, ids) {
  //$('#mini_cart_contents').qtip('api').loadContent('/' + current_store_permalink + '/cart.abbr', {}, 'get');
  $('#mini_cart_contents').qtip('api').updateContent(new_content, false);

  $(ids).each(function() {
    $('.' + in_prefix + this).hide();
    $('.' + add_prefix + this).show();
  });
  flash_cart();
}

function flash_cart() {
	var link_color = jQuery('#cart-count>a').css('color');
  jQuery('#cart-count>a').animate({ color: '#fbdc20' }, 800).animate({ color: link_color}, 800);  
}

function bindChangers() {
  $('.quantity').change(function () {
    $.post(this.form.action, $(this.form).serialize(), function (data, textStatus) {
      $('#cart_contents').html(data);
      bindChangers()
    }, 'html');
  });
}

function bindMiniCartView(css_expression) {
  $(css_expression).qtip({
    show: { solo: true, when: { event: 'mouseover' } },
    hide: { when: 'mouseout', fixed: true, delay: 400 },
    content: {
      url: $(css_expression).attr('rel'),
      method: 'get'
    },
    position: {
       corner: {
          target: 'bottomMiddle',
          tooltip: 'topMiddle'
      }
    },
    style: { 
      'overflow': 'auto',
      'padding': '0px',
      'margin': '0px',
      'background-color': '#ededed',
      width: {
        min: '272em',
        max: '272em'
      },
      height: '220px',
      border: {
        width: '4px',
        color: '#5d5d5d'
      }
    }
  });  
  
}

function init_format_selectors(css_expression) {

  $(css_expression).each(function() {
    $(this).qtip({
      show: { solo: true, when: { event: 'mouseover' } },
      hide: { when: 'mouseout', fixed: true, delay: 400 },
      content: {
        url: $(this).attr('rel'),
        method: 'get'
      },
      position: {
         corner: {
            target: 'bottomLeft',
            tooltip: 'topLeft'
        }
      },
      style: { 
        'overflow': 'auto',
        'padding': '10px',
        'margin': 0,
        'background-color': '#ededed',
        width: {
          min: '310px',
          max: '310px'
        }
      },
      api: {
        beforeShow: function(){
          this.elements.target.addClass('inMenu');
        },
        beforeHide: function(){
          this.elements.target.removeClass('inMenu');
        }
      }
    });
  });
  
}
