var limit = 5
var period = 30000
var last_id = 1

function update() {
    var response = ""
    new Ajax.Request('/latest/pull.js/'+limit+'/'+last_id+'/', {
        method:'get',
        onSuccess:function(transport){
            response = transport.responseText
            response = "var list = " + response
            eval(response)
            last_id = list[0]["pk"]
            
            var img_str = "";
            var href_str = "";
            for (var i=0; i < limit; i++) {
                var j = parseInt(i)+5
                href_str += 'document.links['+j+'].href = "/" + list["'+i+'"]["pk"] + "/";'             
                img_str += 'document.images.i'+i+'.src = list["'+i+'"]["fields"]["url"];'
            }
            
            eval(img_str);
            eval(href_str);

        }
    })

    window.setTimeout(update,period)
}
