jQuery(document).ready(function($){
    $('.oanda-latest-headlines-tweet-slide .tweet-button').click(function() {
        
        var $next_or_prev = $(this).hasClass('tweet-next') ? 'next' : 'prev';
        var $widget_id    = $(this).attr('rel');
        var $count        = $('.tweet-slide-item[rel='+$widget_id+']').size();

        // get the currently visible tweet
        var $visible      = parseInt($('.tweet-slide-item[rel='+$widget_id+']:visible').eq(0).metadata().index);
        
        // selector of the tweet to hide
        var $to_hide = '.tweet-slide-index' + $visible + '[rel='+$widget_id+']';
        
        // selector of the tweet to show
        var $show_index = ( $visible + ( ($next_or_prev == 'next') ? 1 : -1) ) % $count;
        if ($show_index < 0 ) { $show_index = $count - 1; }
        var $to_show = '.tweet-slide-index' + $show_index + '[rel='+$widget_id+']';
        
        $($to_hide + ',' + $to_show).toggle();
        
        return false;
        
    });
    $('.oanda-latest-headlines-tweet-slide .widget-title,.oanda-latest-headlines-tweet-onecol .widget-title')
        .click(function() {
            window.open('http://www.twitter.com/forexrumors','_blank');
        })
        .hover(
            function(){
                $(this).find('.tweet-title-hover').css('color','#009B8E');
            },
            function(){
                $(this).find('.tweet-title-hover').css('color','#000');
            }
        );

});