$(document).ready(function() {
  $("#breadcrumbs a.bcItem:last").addClass('last');
  $("#breadcrumbs").show();
  
  // If more than 1-tier into the categories, move description below products
  if ( typeof(isTopNav) == 'undefined' || !isTopNav ) {
    $("#categoryDescription").appendTo("#products");
    $("#categoryDescription").css('margin', '0 10px');
  }
  $("#categoryDescription").show();
  
  if ( $("#products div.product").length ) {
    $("#products div.product:nth-child(3n)").after('<div class="clear"></div>');
  }
  if ( $("#subcategories div.subcat").length ) {
    // If no products and no "Featured Categories", move it up...
    if ( !$("#products div.product").length && !$("#featureTabs").get(0) ) {
      $("#subcategories").insertBefore("#products");
    }
    $("#subcategories").show();
    if ( !($.browser.msie && $.browser.version <= '6.0') ) {
      $("#subcategories div.subcat:nth-child(2n+1)").after('<div class="clear"></div>');
    }
  }
  
  $(".product").each(function() {
    var price = $(this).find(".priceValue").text();
    price = price.replace(',', '');
    if ( price > 0 ) {
      if ( $(this).find(".listPriceValue").text() != '00.00' && $(this).find(".listPriceValue").text() != $(this).find(".priceValue").text() ) {
        var msrp = $(this).find(".listPriceValue").text();
        msrp = msrp.replace(',', '');
        var savings = parseFloat(msrp) - parseFloat(price);
        $(this).find(".savings").append('$' + Math.floor(savings*100)/100);
        $(this).find(".listPrice").css('visibility', 'visible');
        $(this).find(".savings").css('visibility', 'visible');
      }
      if ( parseFloat(price) >= 99 ) {
        $(this).find(".freeShipping").css('visibility', 'visible');
      } else if ( parseFloat(price) < 10 ) {
        if ( parseFloat(price) >= 1 ) {
          $(this).find(".priceValue").text(parseFloat(price).toFixed(2));
        } else {
          var tmp = parseFloat(price).toFixed(2).toString();
          $(this).find(".priceValue").text(tmp.replace('0.', '.'));
        }
      }
    } else {
      $(this).find(".price").css('display', 'none');
      $(this).find("a img[src*='buy-now']").css('display', 'none');
    }
    var href = $(this).find('.buyNow').attr('href');
    $(this).find('.buyNow').attr('href', href + '?buy-now');
  });
});