window.onload = function() {	
	$('user_action_box').setStyle({top: document.viewport.getScrollOffsets()[1] + 20 + "px"});
}

window.onscroll = function() {
	var box_top = parseInt($('user_action_box').getStyle('top').replace(/px/, ""));	
	var box_where_to_move = parseInt(document.viewport.getScrollOffsets()[1] + 20);
	if(document.viewport.getHeight()>640){
		if(box_top > box_where_to_move){		
			moveUp('user_action_box', box_where_to_move);
		} else {		
			moveDown('user_action_box', box_where_to_move);
		}
	}
}

function moveDown(divName, destination){	
	if(destination == parseInt(document.viewport.getScrollOffsets()[1] + 20)){
		var currentPosition = parseInt($(divName).getStyle('top').replace(/px/, ""));
		var newPosition = currentPosition + 15;
		$(divName).style.top = 	newPosition + "px";
		if (newPosition < destination)
	    {	
	        the_timeout = setTimeout('moveDown(\'' + divName + '\',' +destination + ');' ,100);
	    }
	} else {
		 	
	}
}
 
function moveUp(divName, destination){	
	if(destination == parseInt(document.viewport.getScrollOffsets()[1] + 20)){
		var currentPosition = parseInt($(divName).getStyle('top').replace(/px/, ""));
		var newPosition = currentPosition - 15;
		$(divName).style.top = 	newPosition + "px";
		if (newPosition > destination)
	    {
	        the_timeout = setTimeout('moveUp(\'' + divName + '\',' +destination + ');' , 100);
	    }
	} else {
		 	
	}
}

function hideTopLayer() {
	if(document.getElementById) // gecko(NN6) + IE5+ 
	{ 
		document.getElementById("topLayerSlot").style.display = 'none';
	}
	else if(document.all) //IE 4 
	{ 
		document.all["topLayerSlot"].style.display = 'none'; 
	} 
	else if(document.layers)  // NN4 
	{ 
		document.layers["topLayerSlot"].display = 'none';
	}
}

function getBrowserWindowSize() {
	myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return myHeight;
}

var ns = (navigator.appName.indexOf("Netscape") != -1);
var doc = document;
var px = document.layers ? "" : "px";
function moveTopLayer(id, bannerHeight)
{
	var initialYPos = -bannerHeight;
	var closeButtonHeight = 25;
	var stopYPos = getBrowserWindowSize()/2 - bannerHeight/2 - closeButtonHeight;

	var el=doc.getElementById?doc.getElementById(id):doc.all?doc.all[id]:doc.layers[id];
	window[id + "_object"] = el;
	if(doc.layers) el.style=el;
	el.currentYPos = el.stopYPos = initialYPos;
	el.stylePosPx=function(y){this.style.top=y+px;};
	el.move=function()
	{
	
		var posY;

		posY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ? 
		document.documentElement.scrollTop : document.body.scrollTop;

		posY += stopYPos-initialYPos;
		
		this.currentYPos += (posY + this.stopYPos - this.currentYPos)/8;
		this.stylePosPx(this.currentYPos);
		setTimeout(this.id + "_object.move()", 30);
	}
	return el;
}