$(document).ready(function ()
{

    function mycarousel_initCallback(carousel)
    {
        $('#featured-item-next').bind('click', function ()
        {
            carousel.next();

            // Disable autoscrolling
            carousel.startAuto(0);

            return false;
        });
        $('#featured-item-prev').bind('click', function ()
        {
            carousel.prev();

            // Disable autoscrolling
            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 mycarousel_itemFirstInCallback(carousel, obj, index, state)
    {
        $('#featured-item-dot').removeClass();
        $('#featured-item-dot').addClass("d" + (index - 1));
    };

    setTimeout(function () // Hack to keep jCarousel from conflicting with PIE
    {
        $('#featured_content').jcarousel({
            scroll: 1,
            auto: 6, // Sets the time delay between automatic scrolling of the panel
            wrap: 'both',
            initCallback: mycarousel_initCallback,
            itemFirstInCallback: mycarousel_itemFirstInCallback,
            // This tells jCarousel NOT to autobuild prev/next buttons
            buttonNextHTML: null,
            buttonPrevHTML: null
        });
    }, 500);
});
