/**
 * The default top offset.
 */
var defTopOffset = 0;

/**
 * Main function to scroll all ads.
 */
function scrollAds() {
	scrollLeftAd();
}

/**
 * 
 */
function scrollLeftAd() {
	var leftAd = document.getElementById("leftAd");
	if (leftAd == null) {
		return;
	}
	
	// check for absolute positioning
	if (leftAd.style.position != "absolute") {
		leftAd.style.position = "absolute";
	}
	
	// check for initial offset
	if (defTopOffset == 0) {
		defTopOffset = leftAd.offsetTop;
	}
	
	var scrollTop = 0;
	if(document.documentElement && document.documentElement.scrollTop) {
		scrollTop = document.documentElement.scrollTop;
	} else if(document.body && document.body.scrollTop) {
		scrollTop = document.body.scrollTop;
	} else if(window.pageYOffset) {
		scrollTop = window.pageYOffset;
	} else if(window.scrollY) {
		scrollTop = window.scrollY;
	}
	
	// check for minimum offset
	if (scrollTop < defTopOffset) {
		// do not scroll
		leftAd.style.top = defTopOffset + "px";
		return;
	}
	
	// check bounds
	var parentElement = leftAd.parentNode;
	if ((leftAd.offsetHeight + scrollTop - defTopOffset) >= parentElement.offsetHeight) {
		// bottom reached
		leftAd.style.top = (parentElement.offsetHeight - leftAd.offsetHeight + defTopOffset) + "px";
		return;
	}
	
	// scroll the advertisement
	leftAd.style.top = scrollTop + "px";
}
  