﻿var b1, b2, b3;


$(window).load(function () {
    var links = $('#frontpage-banner .paging a');
    if (links.length > 0) {
        var firstLink = $(".paging a:first");
        var play;
        firstLink.addClass("active");
        var imageWidth = $(".window").width();

        rotate = function () {
            var triggerID = $active.attr("rel") - 1;

            var image_reelPosition = triggerID * imageWidth;

            $(".paging a").removeClass('active');
            $active.addClass('active');

            if (isNaN(image_reelPosition)) {
                image_reelPosition = 0;
            }

            $(".scroller").animate({
                left: -image_reelPosition
            }, 500);
        };

        rotateSwitch = function () {
            clearInterval(play);
            play = setInterval(function () {
                $active = $('.paging a.active').next();
                if ($active.length == 0) {
                    $active = $(".paging a:first");
                }
                rotate();
            }, 5000);
        };

        $(".window").hover(
            function () { clearInterval(play); },
            function () { rotateSwitch(); }
        );

        $(".paging a").click(function () {
            $active = $(this);
            clearInterval(play);
            rotate();
            rotateSwitch();
            return false;
        });

        rotateSwitch();

    } 
});


