﻿var UpdateVelocity = 0;

function UpdateLayout() {
	if(document.getElementById("banners") == null) {
		return;
	}
	
	var top = new Array(0, 0);
	
	if(window.pageYOffset) {
		top[0] = window.pageYOffset - 250;
	} else if(document.body && document.body.scrollTop) {
		top[0] = document.body.scrollTop - 250;
	} else if(document.documentElement && document.documentElement.scrollTop) {
		top[0] = document.documentElement.scrollTop - 250;
	}
	
	if(top[0] < 0) {
		top[0] = 0;
	}
	if(top[0] > document.body.clientHeight - 1400) {
		top[0] = document.body.clientHeight - 1400;
	}
	
	if(!document.getElementById("banners").style.top) {
		top[1] = 0;
	} else {
		top[1] = parseInt(document.getElementById("banners").style.top);
	}
	
	if(top[1] > top[0]) {
		if(UpdateVelocity > 0) {
			UpdateVelocity -= 0.50;
		} else {
			UpdateVelocity -= 0.25;
		}
		
		if(top[0] - top[1] > UpdateVelocity) {
			top[1] = top[0];
		} else {
			top[1] += UpdateVelocity;
		}
	} else if(top[0] > top[1]) {
		if(UpdateVelocity < 0) {
			UpdateVelocity += 0.50;
		} else {
			UpdateVelocity += 0.25;
		};
		
		if(top[0] - top[1] < UpdateVelocity) {
			top[1] = top[0];
		} else {
			top[1] += UpdateVelocity;
		}
	} else {
		UpdateVelocity = 0;
	}
	
	// Fix the placement of the banners.
	document.getElementById("banners").style.top = top[1] + "px";
	
	setTimeout("UpdateLayout()", 10);
}


