var theIMG;
var marginTop = 200;
var paddingTop = 100;

function getObj(name) {
    if (document.getElementById) {
        if (document.getElementById(name))
            return document.getElementById(name);
    } else if (document.all) {
        if (document.all[name])
            return document.all[name];
    } else if (document.layers) {
        if (document.layers[name])
            return document.layers[name];
    }
}

window.onload = function () {
    theIMG = getObj('theIMG');
}

function moveIMG(original, from, to) {
    var allLength = to-original;
    var alreadyWent = from-original;

    var percentWent = alreadyWent / allLength;
    if (percentWent > 1) { return 0; }
    var speed = Math.cos(percentWent) * 12;


    theIMG.style.top = from+'px';
    if (from <= to)
        temp = setTimeout('moveIMG('+original+', '+(from+speed)+', '+to+')', 10);
}

function getPos() {
    var pos = 0;
    if (window.innerHeight) {
        pos = window.pageYOffset;
    } else if (document.documentElement && document.documentElement.scrollTop) {
        pos = document.documentElement.scrollTop;
    } else if (document.body) {
        pos = document.body.scrollTop;
    }
    return pos;
}

function showIMG(text){
    theIMG.innerHTML = text;
    pos = getPos();
    theIMG.style.top = pos-400 + 'px';
    theIMG.style.visibility='visible';
    var to = pos+paddingTop;
    if (to < marginTop) to = marginTop;
    moveIMG(pos-400, pos-400, to);
}

function hideIMG(){
    theIMG.style.visibility='hidden';
}
