/* --- Utilites for sticky ads (scrolling ads) --- */
function ypChaser(sLayerId, iTopOffset, iSlideTime, iCeiling, iFloor) {
	this.chaserDiv = null;
	this.layerId = sLayerId;
	this.topOffset = iTopOffset;
	this.slideTime = iSlideTime;
	this.ceiling = iCeiling;
	this.floor = iFloor;
	this.parentId = "AOS_DesignFrameworkContainer";
	this.parentDiv = null;
	this.parentDivTopOffset = 0;
	ypChaser.registry[ypChaser.registry.length] = this;
}
ypChaser.isIE = window.clientInformation ? true : false;
ypChaser.isN4 = document.layers ? true : false;
ypChaser.isN6 = navigator.appName == "Netscape" && parseInt(navigator.appVersion) >= 5;
ypChaser.isO5 = navigator.userAgent.indexOf("Opera") != -1 && parseInt(navigator.appVersion) >= 4;
ypChaser.registry = new Array( );
ypChaser.callRate = 10;
window.setInterval("ypChaser.timer( )", ypChaser.callRate);
ypChaser.timer = function() {
	var i, chObj;
	for (i = 0; chObj = this.registry[i]; i++) {
		if (!chObj.chaserDiv) chObj.attemptLoad();
		if (chObj.chaserDiv) chObj.main();
	}
}
ypChaser.prototype.attemptLoad = function() {
	var chDiv = null;
	var paDiv = null;
	if (ypChaser.isN6 || ypChaser.isO5) {
		chDiv = document.getElementById(this.layerId);
		paDiv = document.getElementById(this.parentId);
	} else if (ypChaser.isIE) {
		chDiv = document.all[this.layerId];
		paDiv = document.all[this.parentId];
	} else if (ypChaser.isN4) {
		chDiv = document.layers[this.layerId];
		paDiv = document.layers[this.parentId];
	}
	if (chDiv && chDiv != null && paDiv && paDiv != null) {
		this.chaserDiv = chDiv;
		this.parentDiv = paDiv;
		this.initChaserDiv();
	}
}

ypChaser.prototype.initChaserDiv = function() {
	if (this.chaserDiv) {
		if (parseInt(this.ceiling) != this.ceiling-0) {
			this.setCeiling();
		}
		this.chaserDiv.style.position = "absolute";
		if (this.parentDiv) {
			this.parentDivTopOffset = this.parentDiv.offsetTop;
		}
	this.moveTo(this.ceiling + 10 - this.parentDivTopOffset);
	}
}
ypChaser.prototype.setCeiling = function() {
	var curtop = 0;
	var tempChaserDiv = this.chaserDiv;
	if (tempChaserDiv.offsetParent) {
		curtop = tempChaserDiv.offsetTop;
		while (tempChaserDiv = tempChaserDiv.offsetParent) {
			curtop += tempChaserDiv.offsetTop;
		}
	}
	this.ceiling = curtop;
}
ypChaser.prototype.main = function( ) {
	this.currentY = this.getCurrentY();
	var scrollTop = ypChaser.getWindowScroll();
	var newTargetY = scrollTop + this.topOffset;
	var floor = ypChaser.getDocumentHeight() - this.floor;
	newTargetY = Math.max( newTargetY, this.ceiling);
	if (!ypChaser.isO5) {
		newTargetY = Math.min(newTargetY, floor);
	}
	if ( this.currentY != newTargetY ) {
		if ( newTargetY != this.targetY ) {
			this.targetY = newTargetY;
			this.slideInit( );
		}
		this.slide( );
	}
}
ypChaser.prototype.slideInit = function( ) {
	this.A = (this.targetY - this.currentY) / this.slideTime / this.slideTime;
	this.startT = (new Date()).getTime();
	this.startP = this.getCurrentY();
	this.D = this.targetY - this.startP;
}
ypChaser.prototype.slide = function( ) {
	var elapsed = (new Date()).getTime() - this.startT;
	if (elapsed < this.slideTime) {
		this.moveTo(this.D - (Math.round(Math.pow(this.slideTime - elapsed, 2) * this.A)) + this.startP);
	}
}
ypChaser.prototype.moveTo = function(ny) {
	ny = ny - this.parentDivTopOffset;
	if (ypChaser.isN4) this.chaserDiv.top = ny;
	else this.chaserDiv.style.top = ny + "px";
}
ypChaser.prototype.getCurrentY = function() {
	var n = ypChaser.isN4 ? this.chaserDiv.top + this.parentDivTopOffset : parseInt(this.chaserDiv.style.top) + this.parentDivTopOffset;
	return isNaN(n) ? 0 : n;
}
ypChaser.getWindowScroll = function() {
	if (window.pageYOffset) {
		return window.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {
		return document.documentElement.scrollTop;
	} else if (document.body && document.body.scrollTop) {
		return document.body.scrollTop;
	} else {
		return 0;
	}
}
ypChaser.getDocumentHeight = function() {
	if (window.document.height) {
		return window.document.height;
	} else if (document.body.scrollHeight) {
		return Math.max(document.body.scrollHeight, document.body.offsetHeight);
	} else if (document.documentElement.scrollHeight) {
		return Math.max(document.documentElement.scrollHeight, document.documentElement.offsetHeight);
	} else {
		return 5000;
	}
}
