var headline_timer;

function doAnimateHeadline() {
    //Animate headline news
    current_active = $('#headline_control li.active');
    next_active = $('#headline_control li.active').next();
    if(!next_active.get(0)) {
        next_active = $('#headline_control ul').children(":first");
    }
    current_active.removeClass('active');
    next_active.addClass('active');
    changeImageTitle(next_active.attr("news"));

    doTimerHeadline();
}


function doTimerHeadline() {
    headline_timer = setTimeout("doAnimateHeadline()",6000);
}

function changeImageTitle(Id) {
    $('#headline1').hide();
    $('#headline2').hide();
    $('#headline3').hide();
    $('#headline4').hide();

    $('#headline' + Id).fadeIn(750);
    $('#headline' + Id).show();
}


$(document).ready(function() {
    $('#headline1').show();
    $('#headline2').hide();
    $('#headline3').hide();
    $('#headline4').hide();

    $('#headline_control li').click(function() {
        clearTimeout(headline_timer);
        current_click = $(this);
        current_active = $(this).siblings('.active');
        current_active.removeClass('active');
        current_click.addClass('active');
        changeImageTitle(current_click.attr("news"));
        doTimerHeadline();
    });
});

doTimerHeadline();


