var store = new Persist.Store('autoruboards');

/* New Posts */

function hl_new_posts(board, user_id, topic_id, multithread) {
    if (board == '' || user_id == 0 || topic_id == 0 || !checkStorage()) {
        return(false);
    }
    var key = board +'_'+ user_id +'_'+ topic_id;
    var time = 0;
    store.get(key, function(ok, val) {
        if (ok) {
            time = intval(val);
        }
    });
    $('#posts'+ (multithread == 1 ? '_'+ topic_id : '') +' li').each(function(){
        var post_time = parseInt(this.id * 1);
        if (post_time > time) {
            $(this).addClass('new');
        } else if (false) {
            $(this).addClass('visited');
        }
    });
    if (multithread == 0) {
        store.set(key, Math.round(new Date().getTime()/1000.0));
    }
}

function intval(value)
{
    $('<input type="hidden" id="intval_tmp"/>').appendTo('body'); 
    $('#intval_tmp').val(value);
    value = parseInt($('#intval_tmp').val() * 1);
    $('#intval_tmp').remove();
    return(value);
}

function f1(time,multithread)
{
    $('#posts'+ (multithread == 1 ? '_'+ topic_id : '') +' li').each(function(){
        var post_time = parseInt(this.id * 1);
        if (post_time > time) {
            $(this).addClass('new');
        } else if (false) {
            $(this).addClass('visited');
        }
    });
}

/* Announce */

function checkStorage()
{
    return(Persist.type != 'none');
}

function lastAnnounce(time)
{
    if (!checkStorage()) {
        return(false);
    }
    if (time) {
        store.set('last_announce_time', time);
    }
    var last_announce_time = 0;
    store.get('last_announce_time', function(ok, val) {
        if (ok) {
            last_announce_time = intval(val);
        }
    });
    return last_announce_time;
}

function closeAnnounce()
{
    lastAnnounce($('#last_server_announce').val());
    $('.announce_xp, .announce_old').hide();
}