﻿$(document).ready(function () {

    $("#rightInfoBlock5-item").click(function () {
        window.location = $(this).find("a").attr("href");
    });

    ////////////////
    // Initialize //
    ////////////////
    var elements = $('li', $("#slideshow-navigation")).each(function (index) { });
    var iterator = 1;
    var conf_delay = 9000;

    function slideShow() {
        if (iterator == elements.length) iterator = 0;
        switchSlide($(elements[iterator++]), true, 2000);
    }

    function switchSlide(liSelected, animate, duration) {

        var selImg = $("#slideshow_img_container [data-img='img" + liSelected.find("a").attr("data-img-button") + "']");


        $("#slideshow_img_container img.active").fadeOut(duration, function () {
            $(this).attr("class", "");

            $(".slideshow-btn-bekijk").attr("href", liSelected.find("a").attr("href"));

        });

        selImg.fadeIn(duration, function () {
            $(this).attr("class", "active");
        });

        if (!animate) {

            $("#slideshow-text-inner").html("");
            $("#slideshow-text-inner").html(selImg.attr("data-description"));
        }
        else {

            $("#slideshow-text-inner").fadeOut(1000, function () {
                $("#slideshow-text-inner").html(selImg.attr("data-description")).fadeIn(1000);
            });

        }


        $('li', $("#slideshow-navigation")).attr("class", "slideshow-btn");
        liSelected.attr("class", "slideshow-btn active");
    }

    switchSlide($(elements[0]), false, 0);

    var playSlideshow = setInterval(slideShow, conf_delay);


    ////////////////////////////////
    // Show slide by using button //
    ////////////////////////////////
    $(".slideshow-btn").mouseenter(function () {

        iterator = $(this).index() + 1;
        switchSlide($(this), false, 0);

        $('li', $("#slideshow-navigation")).attr("class", "slideshow-btn");
        $(this).attr("class", "slideshow-btn active");

    });

    ////////////////////
    // Pause on hover //
    ////////////////////
    $("#slideshow").hover(function () {
        clearInterval(playSlideshow);
    }, function () {
        playSlideshow = setInterval(slideShow, conf_delay);
    });
});
