﻿var bbTimer = null;
var bbCounter = 0;
var bbOffset = 0;
var bbtop=1;
var initPos = 0;

function updateBillboard() 
{
    var bb=document.getElementById('billboard');
    var window_top=window.bbtop ? bbtop : getY(bb);
   
    if (document.body&&(typeof document.body.scrollTop!='undefined')) 
    {
        if (document.documentElement&&document.documentElement.scrollTop) 
        {
	        window_top=Math.max(document.documentElement.scrollTop,window_top);
        }
        window_top=Math.max(document.body.scrollTop,window_top);
    } 
    else if(window.pageYOffset)
        window_top=Math.max(window.pageYOffset,window_top);
        

    if (bbCounter>1) 
    {
        if (bbCounter == 20)
	        bbOffset = parseInt(bb.style.top) ? parseInt(bb.style.top) : getY(bb);

        bbCounter--;
        window_top = bbOffset + Math.round((window_top-bbOffset)*(Math.cos(Math.PI/20*bbCounter)/2+0.5));
        bbTimer = setTimeout('updateBillboard()', 35);
    }
    
    bb.style.top = window_top+"px";
   
    bbTimer = null;
}

function bbUpdate()
 {
    if (bbTimer != null)
        clearTimeout(bbTimer);

    bbCounter = 20;
    bbTimer = setTimeout('updateBillboard()', 500);
}

function position_billboard() 
{
    var bb=document.getElementById('billboard');
    var scroll_top = 0;
   
    if (document.body&&(typeof document.body.scrollTop!='undefined')) 
    {
        if (document.documentElement&&document.documentElement.scrollTop)
	        scroll_top = document.documentElement.scrollTop;
        else
	        scroll_top = document.body.scrollTop;
    } 
    else if(window.pageYOffset) 
    {
        scroll_top=window.pageYOffset;
    }
    
     
    var frame_top="3";

    if (scroll_top>initPos)
        frame_top=bbtop+(scroll_top-initPos);
        
    bb.style.top = frame_top+'px';
}

function billboard() 
{
    var bb;
    if(!(bb=document.getElementById('billboard')))
        return;

    if ((navigator.appName == "Microsoft Internet Explorer")&&(navigator.platform != "MacPPC")&&(navigator.platform != "Mac68k"))
    {
        bb.style.position = 'relative';
        initPos = getY(bb);
        window.attachEvent("onscroll", bbUpdate);
        window.onresize = function() { updateBillboard(); };
        updateBillboard();
    } else {
        position_billboard();
        bb.style.position = 'relative';
        initPos = getY(bb);
        window.onresize = function() {position_billboard(); };
        window.onscroll = function() {position_billboard(); };
    }
}

function getX(obj) 
{
    return (obj.offsetParent==null ? obj.offsetLeft : obj.offsetLeft+getX(obj.offsetParent));
}

function getY(obj)
{
    return (obj.offsetParent==null ? obj.offsetTop : obj.offsetTop+getY(obj.offsetParent));
}


