var current;

$(document).ready(function(){
    if($("#twitter_update_list").html() != "<li>Loading...</li>"){
        var count = 0;

        $("#twitter_update_list li").each(function(){
                if(count == 0){
                        current = $(this);
                }

                count++;
        });

        $("#twitterbox_inner").html(current.html());
    }

    checkArrows();

    $("a#upTweet").click(function(){
        prevTweet();
        return false;
    });

    $("a#downTweet").click(function(){
        nextTweet();
        return false;
    });
});

function nextTweet(){
    if(current.next().html() != null){
        current = current.next();

        $("#twitterbox_inner").fadeOut("fast", function(){
                $("#twitterbox_inner").html(current.html());
                $("#twitterbox_inner").fadeIn("fast");
        });
    }

    checkArrows();
}

function prevTweet(){
    if(current.prev().html() != null){
        current = current.prev();

        $("#twitterbox_inner").fadeOut("fast", function(){
                $("#twitterbox_inner").html(current.html());
                $("#twitterbox_inner").fadeIn("fast");
        });
    }

    checkArrows();
}

function checkArrows(){
    if(current.prev().html() == null){
        $("#upTweet img").animate({opacity: 0.5});
        $("#downTweet img").animate({opacity: 1});
        //console.log("prev null");
    }
    else if(current.next().html() == null){
        $("#upTweet img").animate({opacity: 1});
        $("#downTweet img").animate({opacity: 0.5});
        //console.log("next null");
    }
    else{
        $("#upTweet img").animate({opacity: 1});
        $("#downTweet img").animate({opacity: 1});
        //console.log("NO null");
    }
}