// Count how many buttons
var btnCount;
var current = 0;

var timeout = 7000;
var sTimeout = (timeout * 2);

var wintime;

jQuery(function(){
    $('.teaserButton').pngFix();

    btnCount = $('.teaserButton').size();

    // Add the hover classes (for IE)
    $('.teaserButton').hover(function(){$(this).addClass('hover');}, function(){$(this).removeClass('hover');});

    $('.teaserButton').click(function(){
        window.clearTimeout(wintime);
        current = $(this).attr('id').substring(4) - 1;
        incTeaser();
    });

    incTeaser();
});

function incTeaser()
{
    if ( (current + 1) > btnCount || (current < 1) ) {
        current = 1;
    } else {
        current = current + 1;
    }
    teaserBtnClick($('#btn-' + current));
    wintime = window.setTimeout('incTeaser()', timeout);
}

function teaserBtnClick(w)
{
    var img = $('#imgPanel img');
    var btn = $(w);
    var ttext = $('#btn-text-' + current);

    img.fadeOut(300, function() {
        $('.teaserText').fadeOut('fast');
        img.attr('src', btn.attr('title'));
        $('.teaserButton').removeClass('active');
        $(w).addClass('active');
    });

    img.fadeIn(300, function(){
        ttext.fadeIn(200);
    });
}
