var rnd = 0;
var speed = 2;
var dir;
var movingRight = true;
var movingLeft = false;
var divtime = 0;
var browserW = 0;
var browserH = 0;

function updateWidth() {
    if (document.all) {
        browserW = document.body.clientWidth;
        browserH = document.body.clientHeight;
    }
    else {
        browserW = innerWidth;
        browserH = innerHeight;
    }
}

function selectYPos () {
    rnd = Math.round(Math.random()*browserH);
    if (rnd > (browserH - 150)) rnd = browserH - 150;
}

function moveDiv()
{
    
    var linguawsi = getStyleObject("linguawsi");
    var the_left = parseInt(linguawsi.left);
    var the_top = parseInt(linguawsi.top);

    if(the_left > browserW)
    {
        the_left = -150;
        selectYPos ();
    }

    the_top = rnd;
    
    if(movingRight)
    {
        the_left += speed;
    }

    if (document.layers)
    {
        linguawsi.left = the_left;
        linguawsi.top = the_top;
    }
    else
    {
        linguawsi.left = the_left + "px";
        linguawsi.top = the_top + "px";
    }
    divtime = setTimeout("moveDiv()",10);
}
 
function stopDiv ()
{
   movingRight = false;
   clearTimeout(divtime);
}

function restartDiv()
{
    movingRight = true;
	clearTimeout(divtime);
    moveDiv();  
}

function getStyleObject(objectId) {
    // cross-browser function to get an object's style object given its id
    if(document.getElementById && document.getElementById(objectId)) {
        // W3C DOM
        return document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
        // MSIE 4 DOM
        return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
        // NN 4 DOM.. note: this won't find nested layers
        return document.layers[objectId];
    } else {
        return false;
    }
} // getStyleObject

window.onload = function() {
    updateWidth();
    var lingua = getStyleObject("linguawsi");
    lingua.visibility = "visible";
    lingua.left = -150;
    selectYPos();
    moveDiv();
}

window.onresize = function()
{
    updateWidth();
}