var driven = require('../'),
    randomName = require('random-name'),
    data = window.data = driven({
        name: randomName(),

        friends: [
            { name: randomName() },
            { name: randomName() },
            { name: randomName() },
            { name: randomName() },
            { name: randomName() },
            { name: randomName() },
            { name: randomName() },
            { name: randomName() }
        ]
    }),
    driver = require('../html')(data),
    friendIndex = 0;

function updateName() {
    data.set('[/name]', randomName());
}

function updateFriend() {
    if (friendIndex > data.get('(length [/friends])')) {
        friendIndex = 0;
    }

    data.set('[/friends/' + (friendIndex++) + '/name]', randomName());
}

window.addEventListener('load', function() {
    driver.attach(document.body);

    updateName();
    setInterval(updateName, 250);
    // setInterval(updateFriend, 50);    
});