// JavaScript Document
// Copyright ProPet 2010+

$(function() {
  //for expand/collapse on brands page
  $('#feeding-program .expanded').show();
  $('.brands-sub .collapsed a.expand-collapse').click(function() {
    $(this).parent().next().slideToggle('400');
    $(this).parent().parent().toggleClass('thumb-enlarged');
    return false;
  });

  $('div.brands-sub div.collapsed a').click(function() {
    $(this).toggleClass('collapsed-open');
    return false;
  });

  //zebra stripe guaranteed analysis tables
  $(".guaranteed-analysis-table tr:nth-child(odd)").addClass("odd");

  //Show Alt tag on Hover for bags
  $('#bags li img').each(function() {
      $(this).wrap('<div class="caption"></div>').after('<div class="bag-name">' + $(this).attr('alt') + '</div>');
      $('.caption').width($(this).width()).children('div').each(function() {
        $(this).css({opacity: 0, display: 'block'});
      });
    });
    // Show captions on hover
    $('.caption').hover(
      function() {$(this).children('div').stop().fadeTo(500, 0.7);},
      function() {$(this).children('div').stop().fadeOut(500);
    });

    //Brand Rotator - Hide/Show   // for brand rotator
    $('.detail-section').hide();
    $('#detail-pro-pet').show();
    $('li#brand-qua').click(function() { $('#brand-details .detail-section').fadeOut(0); $('#detail-quality-care').fadeIn("slow"); $('#thumbs-brands li').removeClass('current'); $(this).addClass('current'); return false; });
    $('li#brand-pro').click(function() { $('#brand-details .detail-section').fadeOut(0); $('#detail-pro-pet').fadeIn("slow"); $('#thumbs-brands li').removeClass('current'); $(this).addClass('current'); return false; });
    $('li#brand-cou').click(function() { $('#brand-details .detail-section').fadeOut(0); $('#detail-country-squire').fadeIn("slow"); $('#thumbs-brands li').removeClass('current'); $(this).addClass('current'); return false; });
    $('li#brand-big').click(function() { $('#brand-details .detail-section').fadeOut(0); $('#detail-big-red').fadeIn("slow"); $('#thumbs-brands li').removeClass('current'); $(this).addClass('current'); return false; });
    $('li#brand-lil').click(function() { $('#brand-details .detail-section').fadeOut(0); $('#detail-lil-red').fadeIn("slow"); $('#thumbs-brands li').removeClass('current'); $(this).addClass('current'); return false; });
    $('li#brand-joy').click(function() { $('#brand-details .detail-section').fadeOut(0); $('#detail-joy').fadeIn("slow"); $('#thumbs-brands li').removeClass('current'); $(this).addClass('current'); return false; });
    $('li#brand-joypro').click(function() { $('#brand-details .detail-section').fadeOut(0); $('#detail-joypro').fadeIn("slow"); $('#thumbs-brands li').removeClass('current'); $(this).addClass('current'); return false; });
    $('li#brand-sma').click(function() { $('#brand-details .detail-section').fadeOut(0); $('#detail-smallanimal').fadeIn("slow"); $('#thumbs-brands li').removeClass('current'); $(this).addClass('current'); return false;});

    //Bag Rotator - Hide/Show
    //propet
    $('li#propet-perf').click(function() { $('#pet-food-copy .detail-bag').fadeOut(0); $('#detail-propet-perf').fadeIn("slow"); $('#bags li a').removeClass('current'); $(this).find('a').addClass('current'); return false; });
    $('li#propet-lamb').click(function() { $('#pet-food-copy .detail-bag').fadeOut(0); $('#detail-propet-lamb').fadeIn("slow"); $('#bags li a').removeClass('current'); $(this).find('a').addClass('current'); return false; });
    $('li#propet-adul').click(function() { $('#pet-food-copy .detail-bag').fadeOut(0); $('#detail-propet-adul').fadeIn("slow"); $('#bags li a').removeClass('current'); $(this).find('a').addClass('current'); return false; });
    $('li#propet-pupp').click(function() { $('#pet-food-copy .detail-bag').fadeOut(0); $('#detail-propet-pupp').fadeIn("slow"); $('#bags li a').removeClass('current'); $(this).find('a').addClass('current'); return false; });
    $('li#propet-dogb').click(function() { $('#pet-food-copy .detail-bag').fadeOut(0); $('#detail-propet-dogb').fadeIn("slow"); $('#bags li a').removeClass('current'); $(this).find('a').addClass('current'); return false; });

    //country squire
    $('li#countrysquire-chun').click(function() { $('#pet-food-copy .detail-bag').fadeOut(0); $('#detail-countrysquire-chun').fadeIn("slow"); $('#bags li a').removeClass('current'); $(this).find('a').addClass('current'); return false; });
    $('li#countrysquire-hipr').click(function() { $('#pet-food-copy .detail-bag').fadeOut(0); $('#detail-countrysquire-hipr').fadeIn("slow"); $('#bags li a').removeClass('current'); $(this).find('a').addClass('current'); return false; });
    $('li#countrysquire-bite').click(function() { $('#pet-food-copy .detail-bag').fadeOut(0); $('#detail-countrysquire-bite').fadeIn("slow"); $('#bags li a').removeClass('current'); $(this).find('a').addClass('current'); return false; });
    $('li#countrysquire-pupp').click(function() { $('#pet-food-copy .detail-bag').fadeOut(0); $('#detail-countrysquire-pupp').fadeIn("slow"); $('#bags li a').removeClass('current'); $(this).find('a').addClass('current'); return false; });
    $('li#countrysquire-smdt').click(function() { $('#pet-food-copy .detail-bag').fadeOut(0); $('#detail-countrysquire-smdt').fadeIn("slow"); $('#bags li a').removeClass('current'); $(this).find('a').addClass('current'); return false; });
    $('li#countrysquire-catf').click(function() { $('#pet-food-copy .detail-bag').fadeOut(0); $('#detail-countrysquire-catf').fadeIn("slow"); $('#bags li a').removeClass('current'); $(this).find('a').addClass('current'); return false; });
    $('li#countrysquire-kitt').click(function() { $('#pet-food-copy .detail-bag').fadeOut(0); $('#detail-countrysquire-kitt').fadeIn("slow"); $('#bags li a').removeClass('current'); $(this).find('a').addClass('current'); return false; });
    $('li#countrysquire-smct').click(function() { $('#pet-food-copy .detail-bag').fadeOut(0); $('#detail-countrysquire-smct').fadeIn("slow"); $('#bags li a').removeClass('current'); $(this).find('a').addClass('current'); return false; });
    $('li#countrysquire-dogb').click(function() { $('#pet-food-copy .detail-bag').fadeOut(0); $('#detail-countrysquire-dogb').fadeIn("slow"); $('#bags li a').removeClass('current'); $(this).find('a').addClass('current'); return false; });

    //quality care plus
    $('li#qualitycare-perf').click(function() { $('#pet-food-copy .detail-bag').fadeOut(0); $('#detail-qualitycare-perf').fadeIn("slow"); $('#bags li a').removeClass('current'); $(this).find('a').addClass('current'); return false; });
    $('li#qualitycare-adul').click(function() { $('#pet-food-copy .detail-bag').fadeOut(0); $('#detail-qualitycare-adul').fadeIn("slow"); $('#bags li a').removeClass('current'); $(this).find('a').addClass('current'); return false; });
    $('li#qualitycare-pupp').click(function() { $('#pet-food-copy .detail-bag').fadeOut(0); $('#detail-qualitycare-pupp').fadeIn("slow"); $('#bags li a').removeClass('current'); $(this).find('a').addClass('current'); return false; });
    $('li#qualitycare-redu').click(function() { $('#pet-food-copy .detail-bag').fadeOut(0); $('#detail-qualitycare-redu').fadeIn("slow"); $('#bags li a').removeClass('current'); $(this).find('a').addClass('current'); return false; });

    //lil red
    $('li#lilred-orig').click(function() { $('#pet-food-copy .detail-bag').fadeOut(0); $('#detail-lilred-orig').fadeIn("slow"); $('#bags li a').removeClass('current'); $(this).find('a').addClass('current'); return false; });
    $('li#lilred-tuna').click(function() { $('#pet-food-copy .detail-bag').fadeOut(0); $('#detail-lilred-tuna').fadeIn("slow"); $('#bags li a').removeClass('current'); $(this).find('a').addClass('current'); return false; });
    $('li#lilred-cann').click(function() { $('#pet-food-copy .detail-bag').fadeOut(0); $('#detail-lilred-cann').fadeIn("slow"); $('#bags li a').removeClass('current'); $(this).find('a').addClass('current'); return false; });

    //big red
    $('li#bigred-pupp').click(function() { $('#pet-food-copy .detail-bag').fadeOut(0); $('#detail-bigred-pupp').fadeIn("slow"); $('#bags li a').removeClass('current'); $(this).find('a').addClass('current'); return false; });
    $('li#bigred-nugg').click(function() { $('#pet-food-copy .detail-bag').fadeOut(0); $('#detail-bigred-nugg').fadeIn("slow"); $('#bags li a').removeClass('current'); $(this).find('a').addClass('current'); return false; });
    $('li#bigred-lamb').click(function() { $('#pet-food-copy .detail-bag').fadeOut(0); $('#detail-bigred-lamb').fadeIn("slow"); $('#bags li a').removeClass('current'); $(this).find('a').addClass('current'); return false; });
    $('li#bigred-grav').click(function() { $('#pet-food-copy .detail-bag').fadeOut(0); $('#detail-bigred-grav').fadeIn("slow"); $('#bags li a').removeClass('current'); $(this).find('a').addClass('current'); return false; });
    $('li#bigred-high').click(function() { $('#pet-food-copy .detail-bag').fadeOut(0); $('#detail-bigred-high').fadeIn("slow"); $('#bags li a').removeClass('current'); $(this).find('a').addClass('current'); return false; });
    $('li#bigred-cann').click(function() { $('#pet-food-copy .detail-bag').fadeOut(0); $('#detail-bigred-cann').fadeIn("slow"); $('#bags li a').removeClass('current'); $(this).find('a').addClass('current'); return false; });

    //joy
    $('li#joy-pupp').click(function() { $('#pet-food-copy .detail-bag').fadeOut(0); $('#detail-joy-pupp').fadeIn("slow"); $('#bags li a').removeClass('current'); $(this).find('a').addClass('current'); return false; });
    $('li#joy-spec').click(function() { $('#pet-food-copy .detail-bag').fadeOut(0); $('#detail-joy-spec').fadeIn("slow"); $('#bags li a').removeClass('current'); $(this).find('a').addClass('current'); return false; });
    $('li#joy-supe').click(function() { $('#pet-food-copy .detail-bag').fadeOut(0); $('#detail-joy-supe').fadeIn("slow"); $('#bags li a').removeClass('current'); $(this).find('a').addClass('current'); return false; });
    $('li#joy-high').click(function() { $('#pet-food-copy .detail-bag').fadeOut(0); $('#detail-joy-high').fadeIn("slow"); $('#bags li a').removeClass('current'); $(this).find('a').addClass('current'); return false; });
    $('li#joy-ener').click(function() { $('#pet-food-copy .detail-bag').fadeOut(0); $('#detail-joy-ener').fadeIn("slow"); $('#bags li a').removeClass('current'); $(this).find('a').addClass('current'); return false; });
    $('li#joy-main').click(function() { $('#pet-food-copy .detail-bag').fadeOut(0); $('#detail-joy-main').fadeIn("slow"); $('#bags li a').removeClass('current'); $(this).find('a').addClass('current'); return false; });
    $('li#joy-basi').click(function() { $('#pet-food-copy .detail-bag').fadeOut(0); $('#detail-joy-basi').fadeIn("slow"); $('#bags li a').removeClass('current'); $(this).find('a').addClass('current'); return false; });
    $('li#joy-comb').click(function() { $('#pet-food-copy .detail-bag').fadeOut(0); $('#detail-joy-comb').fadeIn("slow"); $('#bags li a').removeClass('current'); $(this).find('a').addClass('current'); return false; });

    //joy pro
    $('li#joypro-adul').click(function() { $('#pet-food-copy .detail-bag').fadeOut(0); $('#detail-joypro-adul').fadeIn("slow"); $('#bags li a').removeClass('current'); $(this).find('a').addClass('current'); return false; });
    $('li#joypro-perf').click(function() { $('#pet-food-copy .detail-bag').fadeOut(0); $('#detail-joypro-perf').fadeIn("slow"); $('#bags li a').removeClass('current'); $(this).find('a').addClass('current'); return false; });

    //small animal
    $('li#smallanimal-mpig').click(function() { $('#pet-food-copy .detail-bag').fadeOut(0); $('#detail-smallanimal-mpig').fadeIn("slow"); $('#bags li a').removeClass('current'); $(this).find('a').addClass('current'); return false; });
    $('li#smallanimal-guin').click(function() { $('#pet-food-copy .detail-bag').fadeOut(0); $('#detail-smallanimal-guin').fadeIn("slow"); $('#bags li a').removeClass('current'); $(this).find('a').addClass('current'); return false; });
    $('li#smallanimal-rabb').click(function() { $('#pet-food-copy .detail-bag').fadeOut(0); $('#detail-smallanimal-rabb').fadeIn("slow"); $('#bags li a').removeClass('current'); $(this).find('a').addClass('current'); return false; });
    $('li#smallanimal-fish').click(function() { $('#pet-food-copy .detail-bag').fadeOut(0); $('#detail-smallanimal-fish').fadeIn("slow"); $('#bags li a').removeClass('current'); $(this).find('a').addClass('current'); return false; });





    // for bag rotator
    var selector = $(window.location.hash).selector;
    if ($(selector).length != 0) {
      $('#pet-food-copy .detail-bag').fadeOut(0);
      $(selector).fadeIn("slow");
      //console.log($(selector).parent().parent().children('#bags').find('li img'));
      //$('#bags li img').removeClass('current');
      //$(selector).parent().parent().children('#bags').find('li img#selector').addClass('current');
      return false;
    } else {
      $('#detail-propet-pupp').show();
      $('#detail-countrysquire-chun').show();
      $('#detail-qualitycare-perf').show();
      $('#detail-lilred-orig').show();
      $('#detail-bigred-pupp').show();
      $('#detail-joy-pupp').show();
      $('#detail-joypro-adul').show();
      $('#detail-smallanimal-mpig').show();
    }

    //for home page slider
    $('#slides').after('<div id="scroll-nav">').cycle({
      fx: 'fade',
      timeout: 4000,
      speed: 1000,
      pager:'#scroll-nav'
    });

});


//Product List Links
//$(function() {

//   $('.dog-food-list.propet-products li').click(function(){
//     var currentId = $(this).attr('id');
//     window.location = 'propet.php';
//     $('#pet-food-copy .detail-bag').fadeOut(0);
//     $('#detail-propet-perf').fadeIn("slow");
//     // $('#bags li img').removeClass('current');
//     // $('currentId').find('img').addClass('current');
//     return false;
//   });
// });

jQuery(function($) {
  var $bags = $('ul#bags li'),
      $bag  = $bags.length,
      $size = $bag*128;

  $('ul#bags').css('width', $size);
});

