﻿jQuery(document).ready(function($) {
    // SLIDESHOW STYLES

    $(".paging").show();
    $(".paging a:first").addClass("active");

    var imageWidth = $(".window").width();
    var imageSum = $(".imageReel img").size();
    var imageReelWidth = imageWidth * imageSum;
    var durationBetweenImages = 3000;

    $(".imageReel").css({ 'width': imageReelWidth });

    rotate = function() {

        var triggerID = $active.attr("rel") - 1;
        var image_reelPosition = triggerID * imageWidth;

        $(".paging a").removeClass('active');
        $active.addClass('active');

        $(".imageReel").animate({
            left: -image_reelPosition
        }, 600);

    };

    rotateSwitch = function(duration) {
        durationBetweenImages = duration;
        play = setInterval(function() {
            $active = $('.paging a.active').next();

            if ($active.length === 0) {
                $active = $('.paging a:first');
            }
            rotate();
        }, durationBetweenImages); //Timer speed in milliseconds (3 seconds)
    };

    $(".imageReel a").hover(function() {
        clearInterval(play);
    }, function() {
        rotateSwitch(durationBetweenImages);
    });

    $(".paging a").click(function() {
        $active = $(this);

        clearInterval(play);
        rotate();
        rotateSwitch(durationBetweenImages);
        return false;
    });
});

