function salesSlider_initCallback(carousel) {
    // Disable autoscrolling if the user clicks the prev or next button.
    jQuery('.homeProductsNext').bind('click', function() {
        carousel.next();
        carousel.startAuto(0);
        return false;
    });
    jQuery('.homeProductsPrevious').bind('click', function() {
        carousel.prev();
        carousel.startAuto(0);
        return false;
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

function afterAnimation(carousel){
    if(carousel.autoStopped){
        carousel.startAuto()
    }
}

function salesSlider_itemVisibleInCallbackBeforeAnimation(carousel, item, idx, state) {
    $('.productStickerImage').tooltip({
        delay: 500,
        showURL: false,
        bodyHandler: function() {
            var classText = $(this).parent().find('.productImage').parent().attr('class');
            var parts = classText.split('|');
            var $element = $('<div class="tooltipHeader">' + parts[1] + '</div><div class="contents"><div align="center" class="tooltipImage"><img src="/layout/Cdf/Images/Products/194x194/' + parts[0] + '.png"/></div><div class="tooltipBody">' + parts[2] + '</div></div>');
            return $element;
        }
    });

    $('.productImage').tooltip({
        delay: 500,
        showURL: false,
        bodyHandler: function() {
            var classText = $(this).parent().attr('class');
            var parts = classText.split('|');
            var $element = $('<div class="tooltipHeader">' + parts[1] + '</div><div class="contents"><div align="center" class="tooltipImage"><img src="/layout/Cdf/Images/Products/194x194/' + parts[0] + '.png"/></div><div class="tooltipBody">' + parts[2] + '</div></div>');
            return $element;
        }
    });
    
    // sets the tooltip for the account information.
    $(".explain").tooltip({
        track: true,
        delay: 0,
        showURL: false,
        showBody: " - ",
        fixPNG: true,
        opacity: 0.95
    });
    
};

jQuery(document).ready(function() {
    jQuery('#salesSlider').jcarousel({
        auto: 5,
        wrap: 'circular',
        scroll: 2,
        animation: 'slow',
        initCallback: salesSlider_initCallback,
        itemVisibleInCallback: {
            onBeforeAnimation: salesSlider_itemVisibleInCallbackBeforeAnimation
//            onAfterAnimation: mycarousel_itemVisibleInCallbackAfterAnimation
        }
    });
});
