﻿$(document).ready(function () {

    slider_init();

    var currentIndex = 0;
    var maxIndex = 0;
    var delay = 5000;

    var SLIDER = ".indekijker.top";
    var IMAGES = ".indekijker.top img";
    var LINK = ".indekijker.top a";

    function slider_init() {
        if ($(SLIDER).length > 0) {

            $(LINK).click(function () {
                clearTimeout(scrollTimeout);
            });

            maxIndex = $(IMAGES).length;

            scrollTimeout = setTimeout(function () {
                if (currentIndex + 1 >= maxIndex)
                    currentIndex = 0;
                else
                    currentIndex++;

                $(IMAGES).each(function (i) {
                    if (i == currentIndex) {
                        $(this).show().animate({ opacity: 1, top: 0 });
                        var ref = $(this).attr("ref").split("$_$");
                        if (ref[0] == "") {
                            $(LINK).removeAttr("href");
                            $(this).parent().removeClass("clickable");
                        } else {
                            $(LINK).attr("href", ref[0]);
                            $(this).parent().addClass("clickable");
                        }

                        $(LINK).attr("target", ref[1]);
                    }
                    else
                        $(this).animate({ opacity: 0, top: 20 + "px" }).hide();
                });

                slider_init();

            }, delay);

        }
    }
});



