var TIMEOUT;
var INTERVAL = 7000;

function click_next(){
    if(TIMEOUT)
        clearTimeout(TIMEOUT);
    var next = $('#carousel ul li a.selected').parent().next().find('a').get(0);
    if(!next)
        next = $('#carousel ul li a').get(0);
    $(next).click();
    TIMEOUT = setTimeout('click_next();', INTERVAL)
}

$(function(){
    $('#carousel ul li a').click(function(){
        $('#carousel ul li a').removeClass('selected');
        $(this).addClass('selected');
        $('#carousel .screen').hide();
        $('div[id^=id_carousel_title_]').hide();
        $('#id_carousel_title_' + $(this).attr('rel')).show();
        $('#id_carousel_image_' + $(this).attr('rel')).fadeIn();
        return false;
    });

    TIMEOUT = setTimeout('click_next();', INTERVAL)
});
