function ReadCookie(name)
{
        var label = name + "=";
        var labelLen = label.length;
        var cLen = document.cookie.length;
        var i = 0;

        while (i < cLen) {
                var j = i + labelLen;

                if (document.cookie.substring(i, j) == label) {
                        var cEnd = document.cookie.indexOf(";", j);
                        if (cEnd == -1) cEnd = document.cookie.length;

                        return unescape(document.cookie.substring(j, cEnd));
                }

                i++;
        }

        return "";
}


function SaveCookie(name, value, expire)
{
        var eDate = new Date();
        eDate.setDate(eDate.getDate() + expire);
        document.cookie = name + "=" + value + "; expires=" +  eDate.toGMTString()+ "; path=/";
}


function CheckUIElements(){
    var yMenuFrom, yMenuTo, yButtonFrom, yButtonTo, yOffset, timeoutNextCheck;

    yMenuFrom   = parseInt (RIGHT_BANNER.style.top, 10);
	if(count <2) yMenuTo     = document.body.scrollTop + xTopMargin;
	else yMenuTo     = document.body.scrollTop + 10;

	if (yMenuTo < xTopBase) yMenuTo = xTopBase;
	
    timeoutNextCheck = 500;

    if ( Math.abs (yButtonFrom - (yMenuTo + 152)) < 6 && yButtonTo < yButtonFrom ) {
            setTimeout ("CheckUIElements()", timeoutNextCheck);
            return;
    }

    if ( yButtonFrom != yButtonTo ) {
            yOffset = Math.ceil( Math.abs( yButtonTo - yButtonFrom ) / 10 );
            if ( yButtonTo < yButtonFrom )
                    yOffset = -yOffset;

            divLinkButton.style.top = parseInt (divLinkButton.style.top, 10) + yOffset;

            timeoutNextCheck = 10;
    }
    if ( yMenuFrom != yMenuTo ) {
            yOffset = Math.ceil( Math.abs( yMenuTo - yMenuFrom ) / 20 );

            if ( yMenuTo < yMenuFrom )
                    yOffset = -yOffset;
			
            RIGHT_BANNER.style.top = parseInt (RIGHT_BANNER.style.top, 10) + yOffset;

            timeoutNextCheck = 10;
    }

    Timer1 = setTimeout ("CheckUIElements()", timeoutNextCheck);
}




function ToggleMoveScroll()
{
        if (MOVESCROLL.checked) {
                CheckUIElements();
                SaveCookie("MOVESCROLL", "true", 300);
        }
        else {
                clearTimeout(Timer1);
                RIGHT_BANNER.style.top = xTopBase;
                SaveCookie("MOVESCROLL", "false", 300);
        }
}	


function initiateRightBanner()
{
        if (ReadCookie("MOVESCROLL") == "false") {
            MOVESCROLL.checked = false;
            RIGHT_BANNER.style.top = document.body.scrollTop + xTopPos;
        } else {
            MOVESCROLL.checked = true;
            RIGHT_BANNER.style.top = document.body.scrollTop + xTopPos;
		    CheckUIElements();
        }               
        
        RIGHT_BANNER.style.left = xLeftPos;
         
        return true;
}