function init() {
    // add the random-item box to the page.
    // insert inside the external DIV before the first P of the collection box.
    var eshop = Ext.get('collection-box');
    var lastP = eshop.first('p');
    var randomBox = eshop.createChild({'tag': 'div', 'id': 'random-item'}, lastP);
    var randomAnchor = randomBox.createChild({tag: 'a'});
    var randomImg = randomAnchor.createChild({tag: 'img'});
    // add a space between the IMG and the SPAN fort the pleasure of IE
    randomAnchor.dom.appendChild(document.createTextNode(' '));
    var randomSpan = randomAnchor.createChild({tag: 'span'});
    var randomItem = {
        'a': randomAnchor.dom,
        'img': randomImg.dom,
        'span': randomSpan.dom
    };
    var task = {
        run: function() {
            Ext.Ajax.request({
                url: '/items/random',
                success: function(response, options) {
                    var item = Ext.decode(response.responseText);
                    randomItem.a.href = '/items/' + item.code + '/e-shop';
                    randomItem.img.src = '/items/' + item.code + '/thumb';
                    randomItem.img.alt = item.subject;
                    randomItem.span.innerHTML = item.subject;
                }
            });
        },
        interval: 10000
    };
    Ext.TaskMgr.start(task);
}

Ext.onReady(init);
