var suyveyBannerAdTimerID = null;  	
var surveyBannerAdForIFRM = null;
var suyveyBannerAdTimerIDX = null;

function getWindowHeightforSurvey() {
	var ht = 0;
	if (window.innerHeight) { ht = window.innerHeight; }
	else if (document.documentElement && document.documentElement.clientHeight) {
		ht = document.documentElement.clientHeight; }
	else if (document.body && document.body.clientHeight) {
		ht = document.body.clientHeight; }
	return ht;
}

function getWindowWidthforSurvey() {
	var wd = 0;
	if (window.innerWidth) { wd = window.innerWidth; }
	else if (document.documentElement && document.documentElement.clientWidth) {
		wd = document.documentElement.clientWidth; }
	else if (document.body && document.body.clientWidth) {
		wd = document.body.clientWidth; }
	return wd;
}

function getTopYForSurvey() {
	var y = 0;
	if (document.documentElement && document.documentElement.scrollTop) {
		y = document.documentElement.scrollTop; }
	else if (document.body && document.body.scrollTop) {
		y = document.body.scrollTop; }
	else if (window.pageYOffset) {
		y = window.pageYOffset; }
	else if (window.scrollY) {
		y = window.scrollY; }
	return y;
}

function getLeftXForSurvey() {
	var x = 0;
	if (document.documentElement && document.documentElement.scrollLeft) {
		x = document.documentElement.scrollLeft; }
	else if (document.body && document.body.scrollLeft) {
		x = document.body.scrollLeft; }
	else if (window.pageXOffset) {
		x = window.pageXOffset; }
	else if (window.scrollX) {
		x = window.scrollX; }
	return x;
}

function SuyveyBannerAd(identification, top, left, acceleration, duration) {
	this.id = identification ;
	this.y = top;
	this.x = left;	
	this.ac = acceleration;
	this.du = duration;
	this.getElement = SuyveyBannerAdGetElement;
	this.setLeft = SuyveyBannerAdSetLeft;
	this.setTop = SuyveyBannerAdSetTop;
	this.moveTo = SuyveyBannerAdMoveTo;
	this.moveBy = SuyveyBannerAdMoveBy;
	this.show = SuyveyBannerAdShow;
	this.hide = SuyveyBannerAdHide;
	this.moveY = SuyveyBannerAdMoveY;
	this.moveX = SuyveyBannerAdMoveX;
	this.dy = top;
	this.gsy = top;
	this.dx = left;
	this.gsx = left;
	this.gt = 1000;
	this.gtx = 1000;
	this.gxc1 = 1;
	this.gxc2 = 1;
	this.gyc1 = 1;
	this.gyc2 = 1;
}

function SuyveyBannerAdGetElement(id) {
	var ele = null;
	if (document.getElementById) {
		ele = document.getElementById(id);
	} else if (document.all) {
		ele = document.all[id];
	} else {
	 ele = null;
	}
	return ele;
}

function SuyveyBannerAdSetLeft() {
	var ele = this.getElement(this.id);
	if (!ele) { return; }
	if (this.x) {
		ele.style.left = this.x + "px";
	} else {
		this.x = 0;
		ele.style.left = "0px";
	}
}

function SuyveyBannerAdSetTop() {
	var ele = this.getElement(this.id);
	if (!ele) { return; }
	if (this.y) {
		ele.style.top = this.y + "px";
	} else {
		this.y = 0;
		ele.style.top = "0px";
	}
}

function SuyveyBannerAdMoveTo(l, t) {
	var ele = this.getElement(this.id);
	if (ele) {
		if (l) {
			this.x = l;
			ele.style.left = l + "px";
		}
    	if (t) {
    		this.y = t;
    		ele.style.top = t + "px";
    	}
	}
}

function SuyveyBannerAdMoveBy(l, t) {
	this.moveTo(this.x + l, this.y + t);
}

function SuyveyBannerAdShow() { 
  	var ele = this.getElement(this.id);
  	if (ele) { ele.style.visibility = "visible"; }
}

function SuyveyBannerAdHide() { 
  	var ele = this.getElement(this.id);
  	if (ele) { ele.style.visibility = "hidden"; }
}

function SuyveyBannerAdMoveY() {
	var centerY = (getWindowHeightforSurvey() - 300)/2;
	if (centerY < 0) {centerY = 0; }
	var destY = getTopYForSurvey() + centerY;
	if (destY != this.y) {
		if (destY != this.dy) {
			this.gt = new Date().getTime();
			this.dy = destY;
			var distY = this.dy - this.y;
			var winH = getWindowHeightforSurvey();
			if (Math.abs(distY) > winH) {
				this.gsy = (distY > 0)? (this.dy - winH): this.dy + winH;
			} else { this.gsy = this.y; }
			this.gyc1 = this.gsy + ((1 + this.ac) * (this.dy - this.gsy)/3);
			this.gyc2 = this.gsy + ((2 + this.ac) * (this.dy - this.gsy)/3);
		} 
		var elapsed = new Date().getTime() - this.gt;
		if (elapsed < this.du) {
	    	var y = suyveyBannerAdBezierGetValue(elapsed/this.du, this.gsy, this.dy, this.gyc1, this.gyc2);
	    	this.moveTo(null, y);
	  	} else { this.moveTo(null, this.dy); }
	 }
}

function SuyveyBannerAdMoveX() {
	var centerX = (getWindowWidthforSurvey() - 400)/2;
	if (centerX < 0) {centerX = 0; }
	var destX = getLeftXForSurvey() + centerX;
	if (destX != this.x) {
		if (destX != this.dx) {
			this.gtx = new Date().getTime();
			this.dx = destX;
			var distX = this.dx - this.x;
			var winW = getWindowWidthforSurvey();
			if (Math.abs(distX) > winW) {
				this.gsx = (distX > 0)? (this.dx - winW): this.dx + winW;
			} else { this.gsx = this.x; }
			this.gxc1 = this.gsx + ((1 + this.ac) * (this.dx - this.gsx)/3);
			this.gxc2 = this.gsx + ((2 + this.ac) * (this.dx - this.gsx)/3);
		} 
		var elapsed = new Date().getTime() - this.gtx;
		if (elapsed < this.du) {
	    	var x = suyveyBannerAdBezierGetValue(elapsed/this.du, this.gsx, this.dx, this.gxc1, this.gxc2);
	    	this.moveTo(x, null);
	  	} else { this.moveTo(this.dx, null); }
	 }
}

function suyveyBannerAdBezierB1(t) { return t * t * t }

function suyveyBannerAdBezierB2(t) { return 3 * t * t * (1 - t) }

function suyveyBannerAdBezierB3(t) { return 3 * t * (1 - t) * (1 - t) }

function suyveyBannerAdBezierB4(t) { return (1 - t) * (1 - t) * (1 - t) }

function suyveyBannerAdBezierGetValue(percent, startVal, endVal, c1, c2) {
  	  return endVal * suyveyBannerAdBezierB1(percent) + c2 * suyveyBannerAdBezierB2(percent) + c1 * suyveyBannerAdBezierB3(percent) + startVal * suyveyBannerAdBezierB4(percent);
}


function suyveyBannerAdInit() {
	surveyBannerAdForIFRM = new SuyveyBannerAd("SurveyBannerAd", 0, 0, 1, 1000);
	surveyBannerAdForIFRM.setLeft();
	surveyBannerAdForIFRM.setTop();
	surveyBannerAdForIFRM.show();
	suyveyBannerAdTimerID = window.setInterval("surveyBannerAdForIFRM.moveY()", 10);
	suyveyBannerAdTimerIDX = window.setInterval("surveyBannerAdForIFRM.moveX()", 10);
}

//window.onload = suyveyBannerAdInit;

function suyveyBannerAdSetHidden() {
	surveyBannerAdForIFRM.hide();
	clearInterval(suyveyBannerAdTimerID);
	suyveyBannerAdTimerID = null;
	clearInterval(suyveyBannerAdTimerIDX);
	suyveyBannerAdTimerIDX = null;
}

function suyveyBannerAdPlaceIt()
{
	var theLeft = (getWindowWidthforSurvey() - 400)/2;
	var	theTop = (getWindowHeightforSurvey() - 300)/2;
	if (theLeft < 0) { theLeft = 0; }
	if (theTop < 0) { theTop = 0; }
	surveyBannerAdForIFRM.moveTo(theLeft, theTop);
}

