﻿var bannerIndex = 1;

$(document).ready(function() {

    // Banner Scroller
    $('a.btn1, a.btn2, a.btn3').click(function() {
        $('#bannerScreenContainer').stopTime();
        bannerIndex = parseInt($(this).attr('class').substr(3, 1));
        var bannerPos = 944 * (bannerIndex - 1) * -1;
        $('#bannerScreenContainer').animate({ left: bannerPos + 'px' }, 1000);
        $('a.btn1, a.btn2, a.btn3').removeClass('active');
        $(this).addClass('active');
        setupBannerScroller();
        return false;
    });
    setupBannerScroller();


    // Client Scroller
    var scrollerWidth = 0;
    var box = $('.clientBox ul');
    $('.clientBox img').each(function() { scrollerWidth += $(this).width(); });
    var endPos = (scrollerWidth - 552) * -1;
    
    $('.containerBox .right').hover(function() {
        var currentPos = parseInt(box.css('left').replace('px', ''));
        $(this).everyTime(20, function() {
            if (currentPos > endPos) {
                currentPos -= 4;
                box.css('left', currentPos + 'px');
            }
        });
    }, function() { $(this).stopTime(); });
    
    $('.containerBox .left').hover(function() {
        var currentPos = parseInt(box.css('left').replace('px', ''));
        $(this).everyTime(20, function() {
            if (currentPos < 0) {
                currentPos += 4;
                box.css('left', currentPos + 'px');
            }
        });
    }, function() { $(this).stopTime(); });
    
});

setupBannerScroller = function() {
    
    $('#bannerScreenContainer').everyTime(11000, function() {
        bannerIndex++;
        if (bannerIndex > 3)
            bannerIndex = 1;

        var bannerPos = 944 * (bannerIndex - 1) * -1;
        $(this).animate({ left: bannerPos + 'px' }, 1000);
        $('a.btn1, a.btn2, a.btn3').removeClass('active');
        $('a.btn' + bannerIndex).addClass('active');
    });
    
}
