﻿function Hook() {
    $(document).ready(function () {
        $("#carousel img").click(function () {
            window.location = $(this).attr("href");
        });

        $("#carousel").CloudCarousel({
            xPos: 180,
            yPos: 50,
            buttonLeft: $("#right-but"),
            buttonRight: $("#left-but"),
            reflHeight: 50,
            xRadius: 140,
            yRadius: 30,
            minScale: 0.5,
            onPreviewRotate: function (index) {
                if (index < 0) index = 3 + (index + 1);

                //$("#index0").html(index.toString());
                $("#carousel img:eq(" + index.toString() + ")").fadeTo(200, 0.5);
                $("#carousel-copy .Copy:eq(" + index.toString() + ")").fadeOut();
            },
            onRotate: function (index) {
                if (index < 0) index = 3 + (index + 1);

                var index2 = 5 - index;
                if (index2 == 5) index2 = 1;
                $("#current-index").html(index2.toString());
                $("#carousel img:eq(" + index.toString() + ")").fadeTo(200, 1);
                $("#carousel-copy .Copy:eq(" + index.toString() + ")").fadeIn();
            }
        });

        $("#right-but, #left-but").click(function () {
            clearInterval(intervalTimerId);
            clearTimeout(timeoutId);

            timeoutId = setTimeout(
                function () { intervalTimerId = setInterval(onTick, 8000); },
                5000
            );
        });

        intervalTimerId = setInterval(onTick, 8000);

        $("#current-index").html("1");
        $("#carousel-copy .Copy").first().show().fadeIn();
    });
}

function onTick(){
    $("#right-but").trigger('mouseup');
}

var intervalTimerId, timeoutId;
