var elementCurrent = null;
var elements = new Array();
var elementIndex = 0;
var timer;

function showElementCurrent() {

    jQuery('#flash-content li').hide();
    jQuery('#flash-control a').removeClass('selected');

    jQuery(jQuery(elementCurrent).attr('rel')).show();
    jQuery(elementCurrent).addClass('selected');

}

function play() {

    if(elementIndex >= elements.length) {
        elementIndex = 0;
    }
    elementCurrent = elements[elementIndex];

    showElementCurrent();
    elementIndex++;
    
    timer = setTimeout("play()",3000);
}

function stop() {
    clearTimeout(timer);
}

jQuery(window).ready(function() {

    jQuery('#flash-control a').each(function() {
        elements[elementIndex++] = jQuery(this);
    });
    elementIndex    = 0;
    elementCurrent  = jQuery('#flash-control a#ct-bbc');
    showElementCurrent();

    play();

    jQuery('#flash-control a').mouseenter(function() {
        elementCurrent = jQuery(this);
        showElementCurrent();
    });
    jQuery('#flash').mouseenter(function() {
        stop();
    });
    jQuery('#flash').mouseleave(function() {
        play();
    });
});
