function closeDiv() {
	document.getElementById('floatlayer').style.display = "none";
	clearInterval(intervalFloater);
	return false;
}

window.onerror = null;
var intervalFloater = null;
var topMargin = 100; //posição a partir do topo
var slideTime = 1000; //duração da animação
var ns6 = (!document.all && document.getElementById);
var ie4 = (document.all);
var ns4 = (document.layers);

function layerObject(id,left) { // o segundo parâmetro é a posição a partir da esquerda
	if (ns6) {
		this.obj = document.getElementById(id).style;
		this.obj.left = (left - document.getElementById(id).offsetWidth / 2) + "px";
		return this.obj;
	}
	else if(ie4) {
		this.obj = document.all[id].style;
		this.obj.left = (left - document.all[id].offsetWidth / 2) + "px";
		return this.obj;
	}
	else if(ns4) {
		this.obj = document.layers[id];
		this.obj.left = left - document.layers[id].offsetWidth / 2;
		return this.obj;
	}
}

function layerSetup() {
	floatLyr = new layerObject('floatlayer', pageWidth / 2);
	intervalFloater = window.setInterval(function() { main(); }, 10);
}

function floatObject() {
	if (ns4 || ns6) {
		findHt = window.innerHeight;
	} else if(ie4) {
		findHt = document.body.clientHeight;
   }
}

function main() {
	if (ns4) {
		this.currentY = document.layers["floatlayer"].top;
		this.scrollTop = window.pageYOffset;
		mainTrigger();
	} else if(ns6) {
		this.currentY = parseInt(document.getElementById('floatlayer').style.top);
		this.scrollTop = scrollY;
		mainTrigger();
	} else if(ie4) {
		this.currentY = floatlayer.style.pixelTop;
		this.scrollTop = (document.documentElement) ? document.documentElement.scrollTop : document.body.scrollTop;
		mainTrigger();
   }
}

function mainTrigger() {
	var newTargetY = this.scrollTop + this.topMargin;
	if ( this.currentY != newTargetY ) {
		if ( newTargetY != this.targetY ) {
			this.targetY = newTargetY;
			floatStart();
		}
		animator();
	}
}

function floatStart() {
	var now = new Date();
	this.diferencaY = this.targetY - this.currentY;
	this.periodo = Math.PI / ( 1 * this.slideTime );
	this.inicio = now.getTime();
	if (Math.abs(this.diferencaY) > this.findHt) {
		this.posInicial = this.diferencaY > 0 ? this.targetY - this.findHt : this.targetY + this.findHt;
		this.diferencaY = this.diferencaY > 0 ? this.findHt : -this.findHt;
	} else {
		this.posInicial = this.currentY;
   }
}

function animator() {
	var now = new Date();
	var newY = this.diferencaY * Math.sin(this.periodo * ( now.getTime() - this.inicio )) + this.posInicial;
	newY = Math.round(newY);
	if (( this.diferencaY > 0 && newY > this.currentY ) || ( this.diferencaY < 0 && newY < this.currentY )) {
		if ( ns4 ) document.layers["floatlayer"].top = newY;
		if ( ns6 || ie4 )document.getElementById('floatlayer').style.top = newY + "px";
   }
}

function start() {
	if (ns6||ns4) {
		pageWidth = innerWidth;
		pageHeight = innerHeight;
		layerSetup();
		floatObject();
	} else if(ie4) {
		pageWidth = document.body.clientWidth;
		pageHeight = document.body.clientHeight;
		layerSetup();
		floatObject();
   }
}
