$(document).ready(function(){
  var oldcat = '', i = 0, divId = ["tabOne", "tabTwo", "tabThree"], j = 0;
  $("#featureTabs .featproduct").each(function() {
    if ( oldcat != $(this).find(".featcat").text() ) {
      if ( i > 1 ) {
        j++;
        $("#featureTabs ul").append('<li class="separator"><img src="/product-tab-separator.gif" width="7" height="30" alt="" /></li>');
      }
      $("#featureTabs ul").append('<li><a href="#' + divId[j] + '">' + $(this).find('.featcat').text() + '</a></li>');
    }

    var price = $(this).find(".priceValue").text();
    price = price.replace(',', '');
    if ( $(this).find(".listPriceValue").text() != '' && $(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(".featsavings").append('$' + Math.floor(savings*100)/100);
      $(this).find(".featlistPrice").css('visibility', 'visible');
      $(this).find(".featsavings").css('visibility', 'visible');
    }
    if ( parseFloat(price) > 99 ) {
      $(this).find(".featfreeShipping").css('visibility', 'visible');
    }

    $(this).appendTo("#" + divId[j] + " .tabContent");
    
    oldcat = $(this).find(".featcat").text();
    i++;
  });
  $(".tabContent").append('<div class="clear"></div>');
  
  $("#featureTabs > ul").tabs();
  $("#featureTabs").show();

  $(".ui-tabs-nav a")
    .append('<img src="/product-tab-l.png" class="leftCap" width="15" height="30" alt="" />')
    .append('<img src="/product-tab-r.png" class="rightCap" width="15" height="30" alt="" />');

});