var interval, idx=0, stripped='', terms=[];
function walkHtml( obj ) {
    if(obj.nodeValue && obj.nodeType==3) stripped += obj.nodeValue.toLowerCase()+' ';
    for(var i = 0; i < obj.childNodes.length; i++) walkHtml( obj.childNodes[i] );
}

function boxfill() {
    clearInterval( interval );
    walkHtml(document);
    var word =''
    for(var i=0; i<stripped.length; i++) {
        if( stripped.charAt(i)<'a' || stripped.charAt(i)>'z' ) {
            if(word.length>3) terms[terms.length] = word;
            word = '';
        } else
            word += stripped.charAt(i);
    }
    loadword();
    interval = setInterval( "loadword()", 10000 ); // reload after 60 seconds.
}

function loadword() {
    if(terms.length==0)
        searchfor = "douwe osinga"
    else
        searchfor = terms[Math.floor(Math.random()*terms.length)%terms.length];
    var oTextNode = document.createTextNode("Searched for: "+searchfor);
    var oReplaceNode = document.getElementById("searchLabel").childNodes(0);
    oReplaceNode.replaceNode(oTextNode);
    imagebox.document.body.innerHTML='<iframe width=1000 height=1000 src="http://images.google.com/images?&q='+escape(searchfor)+'"></iframe>';
    imagebox.scrollTo(50,200);
}
interval = setInterval( "boxfill()",100 );
