/*
 * en.js eng lang file
 */
var lang = {
    /* messages */
    message_post_success : 'Successfully posted new post',
    message_posting : 'Posting, please wait ...',
    
    /* error */
    error_post : 'Error posting',
    error_req : 'Error sending request',
    error_password : 'Invalid passwords',
    error_slug : 'Invalid short url',
    error_title : 'Title is required',
    error_slug_exists : 'Short url already exists, pick another',
    
    /* time */
    time_now : 'just now',
    time_min : ['min', 'mins'],
    time_hr :  ['hour', 'hours'],
    time_day : ['day', 'days'],
    time_suf : 'ago',
    
    /* vote */
    vote_up : 'This is OK!',
    vote_down : 'Report this!' 
};

function format_time(time)
{
    var d = new Date();
    var diff = Math.round(d.getTime()/1000) - time;
    var calc, res;
     
    if(diff <= 60) {
        return lang.time_now;
    } else if (diff < 3600) {
        calc = Math.round(diff/60);
        res = calc + ' ' + plural(calc, lang.time_min);
    } else if(diff < 86400) {
        calc = Math.round(diff/3600);
        res = calc + ' ' + plural(calc, lang.time_hr);
    } else {
        calc = Math.round(diff/86400);
        res = calc + ' ' + plural(calc, lang.time_day);
    }
    
    return res + ' ' + lang.time_suf;
}

function plural(num, array)
{
    if(num > 1)
        return array[1];
    else
        return array[0];
}