function viewMore(action) {
    
    var current_block = getCurrent();
    var next_block = getNext();
    var prev_block = getPrev();
    
    var show = (action == "next") ? next_block : prev_block;
    if (show != null) {
        $('.recentapts:eq('+current_block+')').fadeOut("fast", function() {
            hideNav("next");
            hideNav("prev");
            $('.recentapts:eq('+show+')').fadeIn("fast", function() {
                toggleNav();
            });
        });
        $('#recent_nav').fadeOut("fast", function() {
            $('#recent_nav').fadeIn("fast");
        });
    }
}

function getCurrent() {
    var current = null;
    $('.recentapts').each(function(i) {
        if ($(this).css("display") != "none") {
            current = i;
        }
    });
    return current;
}

function numBlocks() {
    return $('.recentapts').size();
}

function getNext() {
    var next = getCurrent()+1;
    if (next <= (numBlocks()-1)) {
        return next;
    }
    else {
        return null;
    }
}

function getPrev() {
    var prev = getCurrent()-1;
    if (prev >= 0) {
        return prev;
    }
    else {
        return null;
    }
}



function toggleNav() {
    var current_block = getCurrent();
    var next_block = getNext();
    var prev_block = getPrev();
    
    if (next_block != null) {
        showNav('next');
    }
    else {
        hideNav('next');
    }
    
    if (prev_block != null) {
        showNav('prev');
    }
    else {
        hideNav('prev');
    }
}

function showNav(type) {
    if (type == "next") {
        var el = $('#recently_next');
        var action = 'next';
        var text = 'next &gt;';        
    }
    else {        
        var el = $('#recently_prev');
        var action = 'prev';
        var text = '&lt; prev';  
    }
    el.html("<a href='#' class='darklink' onclick='viewMore(\""+action+"\"); return false;'>"+text+"</a>");
}

function hideNav(type) {
    if (type == "next") {
        var el = $('#recently_next');     
    }
    else {        
        var el = $('#recently_prev');
    }
    el.html("&nbsp;");
}