// Run JQuery code once the page has loaded
$(document).ready(function() {
  
// Setup shadowbox
  $('tr.prod-main').bind('click', function() {
    
    // Find the correct selectors
    prod_main_id = this.id;
    prod_main_selector = '#' + prod_main_id;
    prod_main_id = prod_main_id.substr(10);
    prod_detail_selector = '#prod-detail_' + prod_main_id;
    
    // Check if this product is already selected
    if ($(prod_main_selector).is('.prod-selected')) {
      // Unselect this product
      $(prod_main_selector).removeClass('prod-selected');
      
      // Hide the details for this product
      $(prod_detail_selector + ' div.prod-detail-div').slideUp('slow', function() {
        $(prod_detail_selector).hide();
      });
      
    } else {
      // Make sure no other products are currently selected
      $('tr.prod-main').removeClass('prod-selected');
      
      // Select this product
      $(prod_main_selector).addClass('prod-selected');
      
      // Hide the details for all products
      //$('tr.prod-detail').hide();
      
      // Check for other visible detail sections, and hide them
      $('tr.prod-detail:visible div.prod-detail-div:visible').slideUp('slow', function() {
        $('tr.prod-detail').not(prod_detail_selector).hide();
        //this.parent.hide();
      });
      
      // Show the details for this product
      $(prod_detail_selector).show();
      $(prod_detail_selector + ' div.prod-detail-div').slideDown('slow');
    }
  });
  
  var handler = function() {
    $(this).removeClass('partnum-selected');
    $(this).unbind('click', handler);
    var destination = $(this).offset().top;
    //alert('destination=' + destination);
    $("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination-100}, 500 );
  };
  
  $('tr.partnum-selected').bind('click', handler);
  
  $('tr.partnum-selected').trigger('click');
  
  //$('.filter_scroll').jScrollPane({scrollbarWidth:14, scrollbarMargin:5});
  
});



