
var bugs = new Array();
var icon_size = 100;
var bugs_count = 20;

/*
 * Objetc: Bug
 */
function Bug_move(){
    var x = (document.body.offsetWidth - icon_size) * Math.random();
    var y = (document.body.offsetHeight - icon_size) * Math.random();
    
    this.id.style.left = x + 'px';
    this.id.style.top = y + 'px';
}

function Bug(id){
    this.move = Bug_move;
    this.id = document.getElementById(id);
    this.move();
    this.id.style.visibility = 'visible';
}

function add_bug(i){
    eval("jsbug_"+i+" = new Bug('bug_"+i+"');");
    bugs.push("jsbug_"+i);
}

function add_buging(){
    for (var i= 0; i < bugs_count; i++){
        img = Math.round(Math.random() * 2)+1;
        document.writeln('<img id="bug_'+i+'" src="http://pub.zeropage.cz/jsfunny/bug'+img+'.gif" class="bug" alt="bug"/>');
        window.setTimeout('add_bug('+i+')', Math.random()*1000);
    }
}

function run() {
    var index = Math.round(Math.random() * (bugs.length -1));
    eval(bugs[index]+".move();");
}

/* po nacteni souboru */
document.writeln('<style>.bug{position: absolute;visibility: hidden;}</style>');
add_buging();
window.setInterval('run()',1000);

