$(function () {

  //------------------------------------------------------------------
  // Put dotted line to separate product rows (4 per row)  
  if ($("#cstm-prodcategory").length > 0) {
    $("#cstm-prodcategory .products a").each(function (idx, el) {
      if (idx > 0 && idx % 4 == 0) {
        $(el).before("<hr />");
      }
    });
  }

  //------------------------------------------------------------------
  // Product detail tabs
  if ($("#cstm-prodinfo").length > 0) {
    $("#cstm-prodinfo .tabs li:first").addClass("first");
    $("#cstm-prodinfo .tabs li:last").addClass("last");
    $('#cstm-prodinfo').qTabs({
      className: 'selected'
      , speed: 'slow'
      , contentClass: 'content'
      , tabList: '#cstm-prodinfo ul.tabs'
      , initialTab: '#info-specs'
      , onBeforeActivate: _hideBVFormBeforeTabClick
      , onAfterActivate: _showBVFormAfterTabClick
    });
  }

  function _hideBVFormBeforeTabClick() {
    // Check if BV form is outside the tab content container.
    // If outside, then hide it since the user has tabbed-away from it.
    if ($("#cstm-prodinfo #BVRRContainer").length == 0) {
      $("#BVRRContainer").hide();
    }
    if ($("#cstm-prodinfo #BVQAContainer").length == 0) {
      $("#BVQAContainer").hide();
    }
  }

  function _showBVFormAfterTabClick() {
    if ($("#info-reviews").is(":visible")) {
      $("#BVRRContainer").show();
    }
    if ($("#info-productqa").is(":visible")) {
      $("#BVQAContainer").show();
    }
  }

  //------------------------------------------------------------------
  // Product FAQs
  $("#cstm-faqs > li > div").hide();
  $("#cstm-faqs > li > a").click(function (e) {
    e.preventDefault();

    $(this).next("div").toggle("fast", function () {
      if ($(this).is(":visible")) {
        var srcpath = window.location.pathname.substring(0, window.location.pathname.lastIndexOf("/")) + "/" + $(this).parent().attr("id");
        pageTracker._trackPageview(srcpath);
      }
    });

  });

  //------------------------------------------------------------------
  // Product detail leftnav
  $(".cstm-products-quicknav #quicknav li a").each(function () {
    if ($(this).children("img").length > 0) {
      $(this).hover(
        function () {
          $(this).children("span").show();
          $(this).children("img").show();
        },
        function () {
          $(this).children("span").hide();
          $(this).children("img").hide();
        }
      );
    }
  });
});
  


