// gives a reference to the element with the given ID
function $(v) { return(document.getElementById(v)); }

// reference to the given element's style object
function $S(v) { return($(v).style); }

// sets object with ID=id, opacity v/100
function uni(v,id,s,top) {
    var ob=$S(id),b=v/100;
    ob.opacity=b;
    //ob.top=top+'px';
    ob.MozOpacity=b;
    ob.KhtmlOpacity=b;
    ob.filter="alpha(opacity="+v+")";
}
function zero(v) { v=parseInt(v); return(!isNaN(v)?v:0); }

function fade(id,ln,s) {
    var top=zero(parseInt($S(id).top));

    function opacity(oStart,oEnd,ln) {
        var speed=Math.round(ln/100),timer=0;

        if(oStart>oEnd) {
            for(i=oStart; i>=oEnd; i--) {
                setTimeout("uni("+i+",'"+id+"','','"+(top--)+"')",timer*speed);
                timer++;
            }
            setTimeout("$S('"+id+"').display='none';",timer*speed);
        } else if(oStart<oEnd) {
            $S(id).display='inline';
            for(i=oStart; i<=oEnd; i++) {
                setTimeout("uni("+i+",'"+id+"','"+1+"','"+(top++)+"')",timer*speed);
                timer++;
            }
        }

    }

    if(s==1 || (!s && $S(id).opacity==0)) opacity(0,100,ln); else opacity(100,0,ln);

}
