﻿var count = -1;
var timer;

function getCount() {
    return count;
}
function setCount(num) {
    count = num;
}
function incCount(num) {
    setCount(getCount() + num);
}

$(document).ready(function () {
    initRotator(count);
    $('#bannerNav a').each(function (index) {
        $(this).click(function () {
            $('#bannerNav a').removeClass("active");
            initRotator(setCount(index));
            return false;
        });
    });
    $('#btnPrevPanel').click(function () {
        incCount(-1);
        initRotator();
        return false;
    });
    $('#btnNextPanel').click(function () {
        incCount(1);
        initRotator();
        return false;
    });
});
function initRotator(auto) {
    if (getCount() < 0) {
        setCount($('#bannerContent li').length - 1);
    }
    if (getCount() != -1)
        $('#bannerNav a').removeClass("active");
    //$('#bannerNav a:eq(' + (getCount()) + ')').removeClass("active");
    if (typeof (auto) != 'undefined')
        incCount(1);
    if (getCount() >= $('#bannerContent li').length)
        setCount(0);

    /*$('#bannerContent li .fadePanel').fadeIn(200, function()
    {
    $('#bannerContent li .fadePanel').fadeOut(200, function() 
    {*/
    $('#bannerContent li').hide();
    $('#bannerContent li:eq(' + getCount() + ')').show();
    /*	});
    });*/
    $('#bannerNav a:eq(' + getCount() + ')').addClass("active");
    clearTimeout(timer);
    timer = setTimeout('initRotator("auto")', 6000);
}

