﻿//slideshow
jQuery(
    function($) {
        jQuery(document).ready(
            function() {

                var index = 1;
                var rotationInterval = $(".rotationInterval").val();
                if (rotationInterval != null)
                    rotationInterval = rotationInterval * 1000;
                else
                    rotationInterval = 5000;
                    
                var t;
                //start slide show automatically
                startSlideshow();
                function startSlideshow() {
                    t = setTimeout(function() { switchSlides() }, rotationInterval);
                }

                //pagination click
                $(".pagination").click(
                  function() {
                      clearTimeout(t);
                      //get index of clicked link                
                      index = $(".pagination").index($(this));
                      switchSlides();
                  }
                );

                //switch slides
                function switchSlides() {
                    //highligh page number
                    $(".pagination").removeClass('active');
                    $(".pagination").eq(index).addClass('active');

                    //show image and text with this index
                    $(".slideshowItem").hide();
                    $(".slideshowItem").eq(index).show();

                    index = (index == $(".pagination").length - 1) ? 0 : index + 1;
                    startSlideshow();
                }

            });
    });
