﻿var currentPageSubnav;

$(document).ready(function() {
/*
    $('.special a').click(function(event) { // cancels promo hover href
        event.stopPropagation();
    });
*/

    $('body.productcategory .prod-details img').click(function() {
        window.location = "https://delmonteregistration.icmodus.com/RegCoupon.aspx?cid=C1063&link=http://www.milkbone.com";
    }).css({
        'cursor': 'pointer'
    });

    $("ul#topnav li").hover(
        function() {
            if (currentPageSubnav &&
                $(this).find("ul").length > 0)
                currentPageSubnav.hide();
            $(this).find("ul").show();
        },
        function() {
            $(this).find("ul").hide();
            if (currentPageSubnav &&
                $(this).find("ul").length > 0)
                currentPageSubnav.show();
        });

// autoscroll
/*var autoTimer;
function letItRide() {
    autoTimer = setInterval('autoshow()', 2000);
}
function stopRiding(){
    clearInterval(autoTimer);
}
letItRide();
*/
/*
 autoshow();

  $('body.home #homebutton').click(function() {
         autoshow();
        return false;
    });
*/


    /*    $(".active").mouseover(function() { // show href in status bar -- not all browsers accept
    window.status = $(this).find("a:first").attr("href");
    })
    .mouseout(function() { window.status = 'Done'; return true; })
    */

    $('.scroll-pane').jScrollPane({ dragMinHeight: 75, dragMaxHeight: 75, showArrows: true }); //stylized scrollbar

    if ($('body.productcategory').hide) // jscrollpane display:none fix
        $('#prod-nutr-info').css({ 'display': 'none' });
    $('#prod-feeding').css({ 'display': 'none' });
    $('#prod-ingredients').css({ 'display': 'none' });

    if ($('body.home').hide) // jscrollpane display:none fix
        $('#tweets-treats').css({ 'display': 'block' });

});

// Set this here for twitter flash and set tweets-treats to display:none
//$(function() { // set this after the divs that need to be display:none;
//$('.scroll-pane').jScrollPane({ dragMinHeight: 75, dragMaxHeight: 75, showArrows: true }); //stylized scrollbar
//});

// carousel nav
function resetnavs() {
    $(".good-give").css({ 'background-position': '0 0' });
    $(".support").css({ 'background-position': '0 -79px' });
    $(".twitter").css({ 'background-position': '0 -158px' });
    $(".facebook").css({ 'background-position': '0 -237px' });
}

$(document).ready(function() {
    $(".good-give").hover(function() {
        if ($(this).hasClass('on') == false)
            $(this).css({ 'background-position': '0 -634px' });
    }, function() {
        if ($(this).hasClass('on') == false)
            $(this).css({ 'background-position': '0 0' });
    });
    $(".support").hover(function() {
        if ($(this).hasClass('on') == false)

            $(this).css({ 'background-position': '0 -713px' });
    }, function() {
        if ($(this).hasClass('on') == false)

            $(this).css({ 'background-position': '0 -79px' });
    });
    $(".twitter").hover(function() {
        if ($(this).hasClass('on') == false)

            $(this).css({ 'background-position': '0 -792px' });
    }, function() {
        if ($(this).hasClass('on') == false)

            $(this).css({ 'background-position': '0 -158px' });
    });
    $(".facebook").hover(function() {
        if ($(this).hasClass('on') == false)

            $(this).css({ 'background-position': '0 -871px' });
    }, function() {
        if ($(this).hasClass('on') == false)

            $(this).css({ 'background-position': '0 -237px' });

    });

    $(".good-give").click(function() {
        cleartimer();
        resetnavs();
        $('.on').removeClass('on');
        $(this).addClass('on');


        $(this).css({ 'background-position': '0 -317px' });
        $(this).show('slide', { direction: 'right' }, 500);
    });
    $(".support").click(function() {
        cleartimer();      
        resetnavs();
        $('.on').removeClass('on');
        $(this).addClass('on');

        $(this).css({ 'background-position': '0 -396px' });
        $(this).show('slide', { direction: 'right' }, 500);
    });
    $(".twitter").click(function() {
        cleartimer(); 
        resetnavs();
        $('.on').removeClass('on');
        $(this).addClass('on');

        $(this).css({ 'background-position': '0 -475px' });
        $(this).show('slide', { direction: 'right' }, 500);
    });
    $(".facebook").click(function() {
        cleartimer();
        resetnavs();
        $('.on').removeClass('on');
        $(this).addClass('on');

        $(this).css({ 'background-position': '0 -554px' });
        $(this).show('slide', { direction: 'right' }, 500);
    });
}); 

//end carousel nav

var flickrpage = 1;

$(function()
{

    /* global nav */
    $('body.home #homebutton').addClass("selected");
    $('body.producthome #productsbutton').addClass("selected");
    $('body.producthome #header #products-sub').css({ 'display': 'block' });
    $('body.producthome #header').removeClass('selected');
    $('body.productcategory #productsbutton').addClass("selected");
    $('body.assistants #canineassistantsbutton').addClass("selected");
    $('body.goodtogive #canineassistantsbutton').addClass("selected");
    $('body.goodtoget #goodtogetbutton').addClass("selected");
    $('body.givegear #givegearbutton').addClass("selected");
    $('body.history #historybutton').addClass("selected");
    $('body.updates #updatesbutton').addClass("selected");
    //    $('body.productcategory #biscuitsbutton').addClass("selected");
    //    $('body.productcategory #crunchytreatsbutton').addClass("selected");
    //    $('body.productcategory #softchewybutton').addClass("selected");
    //    $('body.productcategory #longlastingchewbutton').addClass("selected");
    //    $('body.productcategory #essentialplusbutton').addClass("selected");


    /* google analytics */

    /* promo tracking */
    $('#promo .active').click(function()
    {
        var hreflocation = $(this).find("a:first").attr("href");
        switch (hreflocation)
        {
            case 'Products':
            case '/products':
                pageTracker._trackEvent('PromoUse', 'Click', 'GiveMore');
                break;
            case '/goodtoget':
                // alert('good to get!')
                pageTracker._trackEvent('PromoUse', 'Click', 'Its Good to Get');
                break;
            case '/newessentialsplus':
                //  alert('Essentials plus!')
                pageTracker._trackEvent('PromoUse', 'Click', 'EssentialPlus');
                break;
            case 'http://www.canineassistants.org/cgi-bin/donate':
                //  alert('donate!');
                pageTracker._trackEvent('PromoUse', 'Click', 'Donate to CA');
                break;
            case 'http://www.canineassistants.org/':
                // alert('more info!');
                pageTracker._trackEvent('PromoUse', 'Click', 'More about CA');
                break;
			case 'http://www.pbs.org/dogs-eyes/':
                pageTracker._trackEvent('PromoUse', 'Click', 'PBS');
                break;
            case '/goodtogive':
                // alert('give your support!')
                pageTracker._trackEvent('PromoUse', 'Click', 'More about CA');
                break;
            case '/givegear':
                // alert('give up the gear!')
                pageTracker._trackEvent('PromoUse', 'Click', 'Give Your Support');
                break;
            case '/updates':
                // alert('give up the gear!')
                pageTracker._trackEvent('PromoUse', 'Click', 'Get Updates');
                break;
          //  default: alert('link clicked!');
        }
		if ( $(this).hasClass('promo-2') ) {
        window.open().location = hreflocation; // opens new window
		}
		else {
		 window.location = hreflocation;
		}
        //setTimeout(function() { window.location = hreflocation }, 100);
        return false;
    });

    /* follow dexter link */
    $('#social-content #give-support h4 a').click(function()
    {
        pageTracker._trackEvent('LinkOuts', 'Give Your Support Tab', 'Follow Dexter Button');
    });

    $('#flickrgroupbutton').click(function()
    {
        pageTracker._trackEvent('LinkOuts', 'SitStayPose Tab', 'Flickr Group Button');
    });

    /* product category links */
    $('#products .nav a[title="Biscuits"]').click(function()
    {
        pageTracker._trackEvent('Interactions', 'Products Main Page', 'Biscuits Select');
    });

    $('#products .nav a[title="Soft And Chewy"]').click(function()
    {
        pageTracker._trackEvent('Interactions', 'Products Main Page', 'SoftChewy Select');
    });

    $('#products .nav a[title="Crunchy Treats"]').click(function()
    {
        pageTracker._trackEvent('Interactions', 'Products Main Page', 'CrunchyTreats Select');
    });

    $('#products .nav a[title="Long Lasting Chews"]').click(function()
    {
        pageTracker._trackEvent('Interactions', 'Products Main Page', 'LLChews Select');
    });

    $('#products .nav a[title="Essentials Plus+"]').click(function()
    {
        pageTracker._trackEvent('Interactions', 'Products Main Page', 'Essentials Plus Select');
    });

    $("#good-to-get h3 a:contains('Sign Up')").click(function()
    {
        pageTracker._trackEvent('LinkOuts', 'G2G Page', 'Learn More Button');
    });


    $("#updates h3 a:contains('Sign Up For Updates')").click(function()
    {
        pageTracker._trackEvent('LinkOuts', 'Updates Page', 'Sign Up');
    });


    /* homepage social navs */
    $('#social-nav > div').click(function()
    {
        if ($(this).hasClass('twitter'))
        {

            //   $('#redstripe').animate({ "top": "157px" }, 100);
            $('#tweets-treats').show().siblings().hide();
            $('#tweets-treats').css({ 'left': '0' }); //jscroll-pane fix
            //   $('img').removeClass("image-selected");
            //   $('.twitter img').addClass("image-selected");
            try
            {
                pageTracker._trackPageview('/home/TweetsAboutTreats');
            } catch (err) { }
        }
        else if ($(this).hasClass('good-give'))
        {
            //  $('#redstripe').animate({ "top": "0px" }, 100);
            $('#good-to-give').show().siblings().hide();
            //    $('img').removeClass("image-selected");
            //   $('.good-give img').addClass("image-selected");
            try
            {
                pageTracker._trackPageview('/home/goodtogive');
            } catch (err) { }
        }
        else if ($(this).hasClass('support'))
        {
            //    $('#redstripe').animate({ "top": "78px" }, 100);
            $('#give-support').show().siblings().hide();
            //  $('img').removeClass("image-selected");
            //   $('.support img').addClass("image-selected");
            try
            {
                pageTracker._trackPageview('/home/GiveYourSupport');
            } catch (err) { }
        }
        else if ($(this).hasClass('facebook'))
        {
            //   $('#redstripe').animate({ "top": "235px" }, 100);
            $('#flickr-group').show().siblings().hide();
            //   $('img').removeClass("image-selected");
            //   $('.facebook img').addClass("image-selected");
            try
            {
                pageTracker._trackPageview('/home/SitStayPose');
            } catch (err) { }
        }

        return false;
    }); //end social navs click

    //show the good to give pane
    $('#social-nav > div.good-give').trigger('click');


    //youtube thumbnails
    //  $('#good-to-give .videos-menu ul li ').hide();

    //calculate youtube pagesize
    var youtubepagesize = 5;
    var youtubepage = 0;
    var youtubepages = Math.ceil(($('#good-to-give .videos-menu ul li').length - 2) / youtubepagesize);

    // alert(youtubepages);

    //hide extra thumbnails
    if ($('#good-to-give .videos-menu ul li ').length <= 7)
        $('.videos-menu .back, .videos-menu .fwd').hide();
    else
    {
        //  alert($('#good-to-give .videos-menu ul li ').length);
        $('#good-to-give .videos-menu ul li:gt(5)').hide();
        $('.videos-menu .back, .videos-menu .fwd').show();

    }
    // alert($('.video > ul > li').length);
    if ($('.video ul li ').length <= 7)
        $('.video .back, .video .fwd').hide();
    else
    {
        //  alert($('.video ul li ').length);
        $('.video ul li:gt(5)').hide();
        $('.video .back, .video .fwd').show();

    }

    $('#good-to-give .videos-menu  .back').click(function()
    {

        // alert('hey');
        youtubepage--;
        if (youtubepage == -1) youtubepage = youtubepages - 1;
        //alert(youtubepage);
        $('#good-to-give .videos-menu ul li').hide();

        $('#good-to-give .videos-menu ul li:gt(' + (youtubepagesize * youtubepage) + ')').show();
        $('#good-to-give .videos-menu ul li:gt(' + (youtubepagesize * youtubepage) + youtubepagesize + ')').hide();
        //   
        //        $('#good-to-give .videos-menu ul li:lt(' + (youtubepagesize * youtubepage) - 5 + ')').hide();
        //        $('#good-to-give .videos-menu ul li:gt(' + (youtubepagesize * youtubepage) - 5 + ')').show();
        //        $('#good-to-give .videos-menu ul li:gt(' + youtubepagesize * youtubepage + ')').hide();


        $('.videos-menu .back, .videos-menu .fwd').show();

    });

    $('#good-to-give .videos-menu .fwd').click(function()
    {

        // alert('hey');
        youtubepage++;

        if (youtubepage >= youtubepages) youtubepage = 0;

        //alert(youtubepage);
        $('#good-to-give .videos-menu ul li').hide();

        $('#good-to-give .videos-menu ul li:gt(' + (youtubepagesize * youtubepage) + ')').show();
        $('#good-to-give .videos-menu ul li:eq(' + (((youtubepagesize * youtubepage)) + 1) + ')').addClass('first');

        $('#good-to-give .videos-menu ul li:gt(' + (youtubepagesize * youtubepage) + youtubepagesize + ')').hide();
        //   
        //        $('#good-to-give .videos-menu ul li:lt(' + (youtubepagesize * youtubepage) - 5 + ')').hide();
        //        $('#good-to-give .videos-menu ul li:gt(' + (youtubepagesize * youtubepage) - 5 + ')').show();
        //        $('#good-to-give .videos-menu ul li:gt(' + youtubepagesize * youtubepage + ')').hide();


        $('.videos-menu .back, .videos-menu .fwd').show();

    });




    $('.assistants .video > div   li.prev').click(function()
    {

        // alert('hey');
        youtubepages = Math.ceil(($('.assistants .video > div li').length - 2) / youtubepagesize);

        youtubepage--;

        if (youtubepage == -1) youtubepage = youtubepages - 1;

        //    alert(youtubepage);     

        //alert(youtubepage);
        //        $('.video ul li').hide();

        //        $('.video ul li:gt(' + (youtubepagesize * youtubepage) + ')').show();
        //        $('.video ul li:gt(' + (youtubepagesize * youtubepage) + youtubepagesize + ')').hide();
        //        //   
        //                $('.video ul li:lt(' + (youtubepagesize * youtubepage) - 5 + ')').hide();
        //                $('.video ul li:gt(' + (youtubepagesize * youtubepage) - 5 + ')').show();
        //                $('.video ul li:gt(' + youtubepagesize * youtubepage + ')').hide();


        //        $('.videos-menu .back, .videos-menu .fwd').show();



        $('.assistants .video > div  li').hide();
        $('.assistants .video > div >  li.prev,.assistants .video > div  li.fwd ').show();

        $('.assistants .video > div  ul li:gt(' + (youtubepagesize * youtubepage) + ')').show();
        //     $('.video ul li:eq(' + (((youtubepagesize * youtubepage)) + 1) + ')').addclass('first');

        $('.assistants .video > div  ul li:gt(' + (youtubepagesize * youtubepage) + youtubepagesize + ')').hide();


        $('.assistants .video > div  li.prev ,.assistants .video > div   li.fwd ').show();

    });

    $('.assistants .video > div  ul > li.fwd').click(function()
    {

        //  alert('hey');
        youtubepage++;
        youtubepages = Math.ceil(($('.video li').length - 2) / youtubepagesize);

        if (youtubepage >= youtubepages) youtubepage = 0;

        //        alert(youtubepage);
        //        alert(youtubepages);
        //        alert(youtubepagesize);
        $('.assistants .video > div   ul > li').hide();

        $('.assistants .video > div ul li:gt(' + (youtubepagesize * youtubepage) + ')').show();
        //     $('.video ul li:eq(' + (((youtubepagesize * youtubepage)) + 1) + ')').addclass('first');

        $('.assistants .video > div  ul li:gt(' + (youtubepagesize * youtubepage) + youtubepagesize + ')').hide();


        $('.assistants .video > div  li.prev,.assistants .video > div  li.fwd').show();

    });


    if ($('.assistants .video > div li').length > 7)
    {
        $('.assistants .video > div  li.prev,.assistants .video > div  li.fwd').show();
    }
    else
    {
        $('.assistants .video > div  li.prev,.assistants .video > div  li.fwd').hide();
    }

    /* homepage flickr images */
    $('tr.images td').hide();
    $('tr.images td:eq(1),tr.images td:eq(2)').show();
    $('.user-photo div').html('<img alt="" src="' + $('tr.images td:eq(' + (flickrpage - 1) + ') .smallimage').val() + '"/>');
    $('viewer-nav').html('<p>' + $('tr.images td:eq(' + (flickrpage - 1) + ') .flickrtitle').val() + '</p>');
    $('tr.flickrnav .prev').click(function()
    {
        $('tr.images td').hide();
        flickrpage = flickrpage - 1;

        //if no more prev pages go to last page of photos
        if (flickrpage == 0) flickrpage = $('tr.images td').length - 2;

        $('tr.images td:eq(' + flickrpage + '),tr.images td:eq(' + (flickrpage + 1) + ')').show();

        var bigimage = $('tr.images td:eq(' + (flickrpage - 1) + ') .smallimage').val();
        $('.user-photo div').html('<img alt="" src="' + bigimage + '"/>');
        $('.user-photo p').html($('tr.images td:eq(' + (flickrpage - 1) + ') .flickrtitle').val() + " <a target=\"_blank\" href=\"" + $('tr.images td:eq(' + (flickrpage - 1) + ') .flickerurl').val() + "\">" + $('tr.images td:eq(' + (flickrpage - 1) + ') .username').val() + "</a>");

        /* google tracking */
        pageTracker._trackEvent('Interactions', 'SitStayPose Tab', 'Image Scroll Arrows');


        return false;
    });

    $('tr.flickrnav .next').click(function()
    {
        $('tr.images td').hide();
        flickrpage = flickrpage + 1;

        if (flickrpage == $('tr.images td').length - 1)
            flickrpage = 1;

        $('tr.images td:eq(' + flickrpage + '),tr.images td:eq(' + (flickrpage + 1) + ')').show();

        var bigimage = $('tr.images td:eq(' + (flickrpage - 1) + ') .smallimage').val();
        $('.user-photo div').html('<img alt="" src="' + bigimage + '"/>');
        $('.user-photo p').html($('tr.images td:eq(' + (flickrpage - 1) + ') .flickrtitle').val() + " <a target=\"_blank\" href=\"" + $('tr.images td:eq(' + (flickrpage - 1) + ') .flickerurl').val() + "\">" + $('tr.images td:eq(' + (flickrpage - 1) + ') .username').val() + "</a>");

        /* google tracking */
        pageTracker._trackEvent('Interactions', 'SitStayPose Tab', 'Image Scroll Arrows');

        return false;
    });

    if ($('body.productcategory #essentials-plus').length > 0)
        $('#content').css({ 'height': '578px', 'background': 'white' });

    /* twitter */
    var twitterpage = 0;  //current page of twitter results
    var twitterpages = $('#twitterpages').val();
    $('#tweets-treats > p.prev').hide();

    $('p.more a').click(function()
    {

        //     if (twitterpages > 1) $('#tweets-treats > p.prev').show();
        thisa = $(this);

        //       $('.feed').fadeOut("normal", function() {

        $.ajax({
            type: 'get',
            url: thisa.attr('href').replace('#', '') + '?page=' + ++twitterpage,
            success: function(msg)
            {
                $('.twitter-feed-contain > div:last').after(msg);
                $('.scroll-pane').jScrollPane({ dragMinHeight: 75, dragMaxHeight: 75, showArrows: true }); //stylized scrollbar
            }

        });

        //$('.feed').load(thisa.attr('href').replace('#', '') + '?page=' + ++twitterpage, function() { $('.feed').fadeIn(); });
        //     });

        //remove the next button if last page
        if (twitterpage >= twitterpages - 2) $('#tweets-treats > p.next').hide();


        /* google tracking */
        pageTracker._trackEvent('Interactions', 'Tweets About Treats Tab', 'Next 5 Button');

        return false;

    });

    $('#tweets-treats > p.prev').click(function()
    {

        if (twitterpage <= twitterpages) $('#tweets-treats > p.next').show();

        thisa = $(this).children('a:first');

        $('.feed').fadeOut("normal", function()
        {
            $('.feed').load(thisa.attr('href').replace('#', '') + '?page=' + --twitterpage, function() { $('.feed').fadeIn(); });
        });

        //remove the previous button if first page
        if (twitterpage == 1) $('#tweets-treats > p.prev').hide();

        /* google tracking */
        pageTracker._trackEvent('Interactions', 'Tweets About Treats Tab', 'Prev 5 Button');

        return false;

    });

    //youtube stuff

    //arrows


    $('.videos-menu > ul > li > a:not(:last):not(:first)').click(function()
    {
        var thisvideo = $(this).attr("href").replace("#", "");
        //alert('show video - ' + thisvideo);

        $('img.selected').addClass('off');
        $('img.selected').removeClass('selected');
        $(this).children('img:first').addClass('selected');
        $(this).children('img:first').removeClass('off');

        $('.videos-movie').empty();


        $('.videos-movie').flash({
            src: 'http://www.youtube.com/v/' + thisvideo + "&hl=en&fs=1&hd=1",
            width: 400,
            height: 250,
            background: '#000000',
            wmode: 'transparent'
        });

        return false;
    });

    //youtube stuff
    $('.assistants .video > div  > ul > li > a').click(function()
    {
        var thisvideo = $(this).attr("href").replace("#", "");
        //alert('show video - ' + thisvideo);

        $('img.selected').removeClass('selected');
        $(this).children('img:first').addClass('selected');
        $('.video-movie').empty();


        $('.video-movie').flash({
            src: 'http://www.youtube.com/v/' + thisvideo + "&hl=en&fs=1&hd=1",
            width: 400,
            height: 250,
            background: '#000000',
            wmode: 'transparent'
        });

        return false;
    });

    /* essentials page */
    if ($('#content > #essentials-plus').length > 0)
    {

        $('#essentials-plus').flash({
            src: '/Content/swf/milkbone-chachacha.swf',
            width: 845,
            height: 600
        });
    }

    /* product pages */

    //make this product red
    var thish2 = $('.product-info h2:first').html();
    if ($('.productcategory .group a').length > 0 && thish2.toLowerCase().indexOf('<sup>') > -1)
    {
        thish2 = thish2.substring(thish2.toLowerCase().indexOf('</sup>', 1) + 6, thish2.length);
    }
    $('.productcategory .group a:contains(' + thish2 + ')').addClass("selected");


    //product pagination click 
    $('ul.page li a').click(function()
    {
        thisa = $(this);

        $('ul.page li a').parent().removeClass('selected');
        thisa.parent().addClass('selected');

        $.ajax({
            url: thisa.attr('href').replace('#', ''),
            success: function(msg)
            {

                $('.group:eq(0)').fadeOut("normal");
                $('.group:eq(1)').fadeOut("normal", function()
                {

                    $('.group').remove();
                    thisa.parent().parent().before(msg);

                    //make this product red
                    $('.productcategory .group a:contains(' + $('.product-info h2:first').html() + ')').addClass("selected");

                    //makes product boxes (.active) clickable
                    $('.productcategory .group div.active').click(function()
                    {
                        window.location = $(this).children('p').children('a').attr('href');
                    });

                });

            }
        });

        //fire off tracking
        var thispage = parseInt(thisa.html(), 10);
        var thiscat = $('.product-view > div:first').attr('id');
        pageTracker._trackEvent('Interactions', thiscat + ' Page', 'Select Page ' + thispage);

        return false;
    });



    /* product  nav */
    $('#header ul li ul li a').removeClass('selected');
    if ($('.producthome').length > 0) { $('').addClass('selected'); currentPageSubnav = $("#products-sub"); }
    if ($('.productcategory #biscuits').length > 0) { $('#biscuitsbutton').addClass('selected'); currentPageSubnav = $("#products-sub"); }
    if ($('.productcategory #crunchytreats').length > 0) { $('#crunchytreatsbutton').addClass('selected'); currentPageSubnav = $("#products-sub"); }
    if ($('.productcategory #softandchewy').length > 0) { $('#softchewybutton').addClass('selected'); currentPageSubnav = $("#products-sub"); }
    if ($('.productcategory #longlastingchews').length > 0) { $('#longlastingchewbutton').addClass('selected'); currentPageSubnav = $("#products-sub"); }
    if ($('.productcategory #essentialsplus').length > 0) { $('#essentialplusbutton').addClass('selected'); currentPageSubnav = $("#products-sub"); }

    if ($('.assistants').length > 0) { $('#canineassistantsbutton-sub').addClass('selected'); currentPageSubnav = $("#canine-assis-sub"); }
    if ($('.goodtogive').length > 0) { $('#goodtogivebutton').addClass('selected'); currentPageSubnav = $("#canine-assis-sub"); }

    if (currentPageSubnav) currentPageSubnav.show();

    $('#productinfo > div > h3').hide();
    $('#productinfo > div > p').hide();
    $('.productdesc').show();

    //makes product boxes (.active) clickable
    $('.productcategory .group div.active').click(function()
    {
        window.location = $(this).children('p').children('a').attr('href');
    });



    /* $('.productcategory .prod-details img').click(function() {
    window.location = "https://delmonteregistrationuat.icmodus.com/RegCoupon.aspx?cid=C1063&link=http://www.milkbone.com&bhcp=1";
    }).css({
    'cursor': 'pointer'
    }); */


    $('.product-details li a').click(function()
    {

        $('.product-details li a').removeClass('selected');
        $(this).addClass('selected');
        var thistab = $(this).attr("href"); //.replace("#", ".");

        //hide all info tabs
        $('.product-info > div').hide();
        //show selected one
        $(thistab).show();


        var thispage = $(this).html();
        var thiscat = $('.product-view > div:first').attr('id');
        var thisproduct = $('.product-info h2:first').html();

        try
        {
            pageTracker._trackPageview('/Products/' + thiscat + '/' + thispage + '/' + thisproduct);
        } catch (err) { }

        return false;
    });



    /* get gear */

    $('body.givegear .product-nav a').click(function()
    {

        $('body.givegear .product-nav a.selected').removeClass('selected');
        $(this).addClass('selected');

        var thisproduct = $(this).attr('href').replace('#', '');
        $('.product-view > div').hide();
        $('.product-view > div#' + thisproduct).show();

        pageTracker._trackEvent('Gear', 'Order', thisproduct);
        return false;

    });

    $('body.givegear .product-nav img').click(function()
    {

        $(this).siblings('p').children('a:first').trigger('click');
        return false;

    });





});
	
	
// simple show/hide
	
function showDiv(divid){
   if (document.layers) document.layers[divid].display="block";
   else document.getElementById(divid).style.display="block";
}

function hideDiv(divid){
   if (document.layers) document.layers[divid].display="none";
   else document.getElementById(divid).style.display="none";

}

/* autoscroll hover functionality */

var timers = [];
function autoshow(){
    var t = 500;
    for(var i=0; i<4; i++){
        timers[i] =  setTimeout("update" + (i + 1) + "()", t);
        t += 500;
    }
}
function cleartimer(){
    for(var i=0; i<4; i++){
        clearTimeout(timers[i]);
    }
}
function update1(){
	$(".support").css({ 'background-position': '0 -713px' });
}
function update2(){
	$(".support").css({ 'background-position': '0 -79px' });
    $(".twitter").css({ 'background-position': '0 -792px' });
}
function update3(){
	$(".twitter").css({ 'background-position': '0 -158px' });
    $(".facebook").css({ 'background-position': '0 -871px' });
}
function update4(){
	$(".facebook").css({ 'background-position': '0 -237px' });
}


/* autoscroll sliding door functionality */

/*var timer1;
var timer2;
var timer3;
var timer4;

function autoshow() {
    timer1 = setTimeout(function() {
        $(".support").trigger('click');
        timer2 = setTimeout(function() {
            $(".twitter").trigger('click');
            timer3 = setTimeout(function() {
                $(".facebook").trigger('click');
                timer4 = setTimeout(function() {
                    $(".good-give").trigger('click');

                }, 500);
            }, 500);
        }, 500);
    }, 500);

}

function cleartimers() {

    clearInterval(timer1);
    clearInterval(timer2);
    clearInterval(timer3);
    clearInterval(timer4);
}
*/